LInq 使用where过滤,匿名类型来查找想要的数据。


 

 static void Main(string[] args)
        {
            List
<Person> personL = new List<Person>();
            personL.Add(
new Person("wtq""""13616009873"23));
            personL.Add(
new Person("wta""""13616009871"24));
            personL.Add(
new Person("wtb""""13616009872"26));
            personL.Add(
new Person("wtc""""13616009873"25));
            personL.Add(
new Person("wtd""""13616009874"27));
            personL.Add(
new Person("wte""""13616009875"28));
            personL.Add(
new Person("wtf""""13616009876"29));
            personL.Add(
new Person("wtg""""13616009877"30));
            personL.Add(
new Person("wth""""13616009878"23));

            var pr 
= from n in personL
                     
where n.Age == 23
                     select 
new { myname = n.Name, mysex = n.Sex };

            
foreach (var item in pr)
            {
                Console.WriteLine(item.myname
+" "+item.mysex);
            }

            Console.ReadLine();

        }

相关文章:

  • 2021-11-05
  • 2022-12-23
  • 2021-06-21
  • 2021-07-14
  • 2021-06-09
  • 2022-01-18
  • 2021-07-20
  • 2021-07-07
猜你喜欢
  • 2022-12-23
  • 2021-07-23
  • 2022-01-03
  • 2019-11-20
  • 2021-08-22
  • 2021-11-06
  • 2022-12-23
相关资源
相似解决方案