Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取具有匹配属性的对象列表 公共类人物 { 公共字符串名称{get;set;} } List listOfPerson=新列表(); 添加(newperson(){Name=“Pramod”}); 添加(newperson(){Name=“Prashant”}); 添加(newperson(){Name=“Sachin”}); 添加(newperson(){Name=“Yuvraj”}); 添加(newperson(){Name=“Virat”});_C#_Linq - Fatal编程技术网

C# 获取具有匹配属性的对象列表 公共类人物 { 公共字符串名称{get;set;} } List listOfPerson=新列表(); 添加(newperson(){Name=“Pramod”}); 添加(newperson(){Name=“Prashant”}); 添加(newperson(){Name=“Sachin”}); 添加(newperson(){Name=“Yuvraj”}); 添加(newperson(){Name=“Virat”});

C# 获取具有匹配属性的对象列表 公共类人物 { 公共字符串名称{get;set;} } List listOfPerson=新列表(); 添加(newperson(){Name=“Pramod”}); 添加(newperson(){Name=“Prashant”}); 添加(newperson(){Name=“Sachin”}); 添加(newperson(){Name=“Yuvraj”}); 添加(newperson(){Name=“Virat”});,c#,linq,C#,Linq,我想要一个LINQ解决方案,它将返回名称属性以“pra”开头的对象列表。Thomas的解决方案使用LINQ扩展方法,这使用完整的LINQ查询语法 var results = listOfPerson.Where( p => p.Name.StartsWith("pra", StringComparison.CurrentCultureIgnoreCase)); foreach(Person p in results) { ... } Thomas的解决方案使用LINQ扩

我想要一个LINQ解决方案,它将返回名称属性以“pra”开头的对象列表。

Thomas的解决方案使用LINQ扩展方法,这使用完整的LINQ查询语法

var results = listOfPerson.Where(
    p => p.Name.StartsWith("pra", StringComparison.CurrentCultureIgnoreCase));

foreach(Person p in results)
{
    ...
}

Thomas的解决方案使用LINQ扩展方法,这使用完整的LINQ查询语法

var results = listOfPerson.Where(
    p => p.Name.StartsWith("pra", StringComparison.CurrentCultureIgnoreCase));

foreach(Person p in results)
{
    ...
}
var query = from x in listOfPerson 
            where x.Name.StartsWith("pra")
            select x;

foreach(var p in query)
{
    ...
}