我有如下单词列表:
List<string> words = new List<string>();
words.Add("abet");
words.Add("abbots"); //<---Return this
words.Add("abrupt");
words.Add("abduct");
words.Add("abnats"); //<--return this.
words.Add("acmatic");
我想返回所有以字母“a”开头且“t”作为第 5 个字母的 6 个字母的单词,结果应返回单词“abbots”和“abnats”。
var result = from w in words
where w.StartsWith("a") && //where ????
我需要添加什么子句才能满足第 5 个字母是“t”的要求?
最佳答案
var result = from w in words
where w.Length == 6 && w.StartsWith("a") && w[4] == 't'
select w;
关于c# - 如何返回以特定字符开头和结尾的所有单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7011549/