Assign values of array to separate variables in one line

前端 未结 8 1507
感情败类
感情败类 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 01:07

    You can do this in C#

    string str1 = "hey", str2 = "now";
    

    or you can be fancy like this

            int x, y;
            int[] arr = new int[] { x = 1, y = 2 };
    

提交回复
热议问题