c#-Linq-扩展方法

代码

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

namespace Linq2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var names = new List<string> { "zhang shan", "zhang shan2", "wang wu" };
            var namesWithz = (from n in names where n.StartsWith("z") select n).ToList();
            foreach(string s in namesWithz)
            {
                Console.WriteLine(s);
            }
            Console.ReadLine();
        }
    }
}

运行结果

Hello World!
zhang shan
zhang shan2
发布了476 篇原创文章 · 获赞 38 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/xie__jin__cheng/article/details/104051737