星空网 > 软件开发 > 操作系统

C# Lambda 实例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lambda
{
    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }

    class Program
    {
        public static List<Person> PersonsList()
        {
            List<Person> persons = new List<Person>();
            for (int i = 0; i < 7; i++)
            {
                Person p = new Person() { Name = i + "-Son", Age = 8 - i, };
                persons.Add(p);
            }
            return persons;
        }

        static void Main(string[] args)
        {
            List<Person> persons = PersonsList();
            persons = persons.Where(p => p.Age > 6).ToList();       //所有Age>6的Person的集合
            Person per = persons.SingleOrDefault(p => p.Age == 1);  //Age=1的单个people类
            persons = persons.Where(p => p.Name.Contains("Son")).ToList();   //所有Name包含儿子的Person的集合
            Console.ReadLine();
        }
    }
}




原标题:C# Lambda 实例

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

CNET:https://www.goluckyvip.com/tag/17134.html
CNE递一物流:https://www.goluckyvip.com/tag/17135.html
cnf空运:https://www.goluckyvip.com/tag/17136.html
COACH:https://www.goluckyvip.com/tag/17137.html
COAL N TERRY:https://www.goluckyvip.com/tag/17138.html
COA证书:https://www.goluckyvip.com/tag/17139.html
价格翻了8倍,居然还有人买,秘诀在这里。:https://www.kjdsnews.com/a/1836642.html
欧洲B2B电商市场有待挖掘!销售总额将达1.7万亿欧元:https://www.kjdsnews.com/a/1836643.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流