.txt文件中有一个单词列表。我只想在console中显示以字母“R”开头并保持字母顺序的单词。示例:'Rav‘'Ret’'Ril‘
static void Main(string[] args)
{
StreamReader objReader = new StreamReader(
@"C:\Users\thoma\Documents\Visual Studio 2019\Backup Files\data.txt");
string orden = "";
List<string> arrText = new List<string>();
while (orden != null)
{
orden = objReader.ReadLine();
if (orden != null) arrText.Add(orden);
}
objReader.Close();
foreach (string sOutput in arrText)
Console.WriteLine(sOutput);
Console.WriteLine("Order alphabetically ascending press 'a': ");
Console.WriteLine("Ordener descendant alphabetical press 'b': ");
instruccion = Console.ReadLine();
if (instruccion == "a"){
var resultList = arrText.Where(o => o.StartsWith("r"));
Console.WriteLine(resultList);
//string ascending = string.Format("{0}{1}{0}", "'", string.Join("','", arrText.OrderBy(x => x)));
}
Console.ReadLine();
}
}
}
这段代码给我的结果是'System.Linq.Enumerable+WhereListIterator‘
感谢您的帮助
https://stackoverflow.com/questions/54935400
复制相似问题