Lambda表示式where過濾資料

Insus.NET發表於2017-12-30

使用Lambda的表示式來過濾符合條件的資料。下面的程式碼實現,是把字元陣列中,把名字長度等於3元素找出來。

 

class Bv
    {
        public void LambdaExpression()
        {
            string[] names = new string[] { "insus", "leo", "yang", "Joe", "Michael" };

            var result = names.Where(x => x.Length == 3);

            foreach (string s in result)
            {
                Console.WriteLine(s);
            }
        }

    }
Source Code

 

執行結果:

 

相關文章