返回布爾值,判斷集合中是否有元素滿足某一條件。 source code: IEnumerable<string> str = new List<string> { "asdf","fgsdfg","tyuiu","ryury","ituyitu" }; if (str.Any(x => x.Ends ...
返回布爾值,判斷集合中是否有元素滿足某一條件。
source code:
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
IEnumerable<string> str = new List<string> { "asdf","fgsdfg","tyuiu","ryury","ituyitu" }; if (str.Any(x => x.EndsWith("iu"))) { Write("true"); } else { Write("false"); }View Code
source code:
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
IEnumerable<string> str = new List<string> { "asdf","fgsdfg","tyuiu","ryury","ituyitu" }; //if (str.Any(x => x.EndsWith("iu"))) //{ // Write("true"); //} //else //{ // Write("false"); //} bool blnResult = str.Any(); blnResult = str.Any<string>((s) => { return s.LastIndexOf("iu") > 0; }); if (blnResult) { Write("true"); } else { Write("false"); }View Code