C# Print list of string array

后端 未结 5 2058
说谎
说谎 2021-01-02 01:02

I\'m very new to c# and have a question, how do I print list of string arrays? I can do it from string[] using Console.WriteLine, but if I do that for list with forEach it j

5条回答
  •  伪装坚强ぢ
    2021-01-02 01:48

    In a string array to get the index you do it:

    string[] names = new string[3] { "Matt", "Joanne", "Robert" };
    
    int counter = 0;
    foreach(var name in names.ToList())
    {
     Console.WriteLine(counter.ToString() + ":-" + name);
     counter++;
    }
    

提交回复
热议问题