我希望能够在我使用 C# 读取的文件中找到所有单词“Monday”。我可以读取文件,我可以读取第一个星期一并接收它的索引值,但我想要文件中所有星期一的索引值。
if (ElementS == "2")
{
Console.WriteLine("Enter The name of the day e.g. Monday, Tuesday etc.");
string ElementA = Convert.ToString(Console.ReadLine());
foreach (string Monday in DayLines)
{
string Mday = "Monday";
int Found = Search(DayLines, Mday);
Console.WriteLine("The index is {0}", Found);
}
它给出的输出是这样的:
// The index is 0
它对文件中的每个元素都这样做,而不仅仅是星期一。