使用StartsWith比较字符串数组的值我有一个数组:string[]exceptions=newstring[]{"one",two","one_1","three"};..我希望能够说:varresult=fromcinmyCollectionwherenotc.Property[3].Value.StartWith(exceptions)selectc;所以我想过滤myCollection仅显示那些Properties[3].ValuedoesnotStartWitharecordofavalueintheexceptionarray.我知道StartsWith不收集集合,所以我不确定LINQ是否可行。这在LINQ中可行吗?!或者我是在试图构建我的问题转换为LINQ解决方案?编辑:我应该说包含不是一个选项,因为我只想排除其属性以异常字符串开头的元素。varresult=myCollection.Where(c=>exceptions.All(e=>!c.Property[3].Value.StartsWith(e));试试这个:string[]exceptions=newstring[]{"one","two","one_1","三"};varresult=fromcinmyCollectionwhere!exceptions.Any(exception=>c.Property[3].Value.StartsWith(exception))selectc;您可以使用IndexOfAny(并检查结果是否为索引位置零),因为它需要一个集合……您可以选择不需要的项目集合,然后执行IEnumerable.Except()。我应该是这样看的:以上是C#学习教程:使用StartsWith与字符串数组比较值的所有内容分享,如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注—varresult=fromcinmyCollectionwherenotc.Property[3].Value.StartWith(exceptions)选择c;varfinalResult=myCollection.Except(myCollection.Select(i=>i.StartWith(exceptions)));varresult=myCollection.where(rs=>exceptions.where(rs1=>!rs.property[3].value.startsWith(rs1)))本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
