Assign values of array to separate variables in one line

前端 未结 8 1526
感情败类
感情败类 2020-12-11 00:24

Can I assign each value in an array to separate variables in one line in C#? Here\'s an example in Ruby code of what I want:

irb(main):001:0> str1, str2          


        
8条回答
  •  余生分开走
    2020-12-11 00:48

    This is not possible in C#.

    The closest thing I can think of is to use initialization in the same line with indexs

    strArr = new string[]{"foo","bar"};
    string str1 = strArr[0], str2 = strArr[1];
    

提交回复
热议问题