⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmcustomclass.cs

📁 移动设备的 LINQ 编程介绍 .NET Compact Framework 版 LINQ 的特性
💻 CS
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Demo1___LinqToObjects
{
	public partial class FrmCustomClass : Form
	{
		private List<Student> students;

		class Student
		{
			public string First { get; set; }
			public string Last { get; set; }
			public int ID { get; set; }
			public List<int> Scores;
		}

		public FrmCustomClass()
		{
			InitializeComponent();

			// Create a data source by using a collection initializer.
			students = new List<Student>
			{
			   new Student { First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97, 92, 81, 60}},
			   new Student { First="Claire", Last="O’Donnell", ID=112, Scores= new List<int> {75, 84, 91, 39}},
			   new Student { First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {88, 94, 65, 91}},
			   new Student { First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {97, 89, 85, 82}},
			   new Student { First="Debra", Last="Garcia", ID=115, Scores= new List<int> {35, 72, 91, 70}},
			   new Student { First="Fadi", Last="Fakhouri", ID=116, Scores= new List<int> {99, 86, 90, 94}},
			   new Student { First="Hanying", Last="Feng", ID=117, Scores= new List<int> {93, 92, 80, 87}},
			   new Student { First="Hugo", Last="Garcia", ID=118, Scores= new List<int> {92, 90, 83, 78}},
			   new Student { First="Lance", Last="Tucker", ID=119, Scores= new List<int> {68, 79, 88, 92}},
			   new Student { First="Terry", Last="Adams", ID=120, Scores= new List<int> {99, 82, 81, 79}},
			   new Student { First="Eugene", Last="Zabokritski", ID=121, Scores= new List<int> {96, 85, 91, 60}},
			   new Student { First="Michael", Last="Tucker", ID=122, Scores= new List<int> {94, 92, 91, 91}}
			};
		}

		private void menuItem1_Click(object sender, EventArgs e)
		{
			// Create the query.
			// studentQuery is an IEnumerable<Student>
			var studentQuery =
				from student in students
				where student.Scores[0] > 90
				select new
				{
					ID = student.ID,
					Last = student.Last,
					First = student.First
				};

			dataGrid1.DataSource = studentQuery.ToList();
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -