Easiest way to parse a comma delimited string to some kind of object I can loop through to access the individual values?

前端 未结 7 673
予麋鹿
予麋鹿 2020-11-28 06:57

What is the easiest way to parse a comma delimited string list of values into some kind of object that I can loop through, so that I can access the individual values easily?

7条回答
  •  北海茫月
    2020-11-28 07:35

    Use Linq, it is a very quick and easy way.

    string mystring = "0, 10, 20, 30, 100, 200";
    
    var query = from val in mystring.Split(',')
                select int.Parse(val);
    foreach (int num in query)
    {
         Console.WriteLine(num);
    }
    

提交回复
热议问题