C# Syntax - Split String into Array by Comma, Convert To Generic List, and Reverse Order

后端 未结 6 590
Happy的楠姐
Happy的楠姐 2020-12-07 19:49

What is the correct syntax for this:

IList names = \"Tom,Scott,Bob\".Split(\',\').ToList().Reverse();

What am I

6条回答
  •  轮回少年
    2020-12-07 20:11

    I realize that this question is quite old, but I had a similar problem, except my string had spaces included in it. For those that need to know how to separate a string with more than just commas:

    string str = "Tom, Scott, Bob";
      IList names = str.Split(new string[] {","," "},
      StringSplitOptions.RemoveEmptyEntries);
    

    The StringSplitOptions removes the records that would only be a space char...

提交回复
热议问题