Assign values of array to separate variables in one line

前端 未结 8 1517
感情败类
感情败类 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:43

    No, but you can initialize an array of strings:

    string[] strings = new string[] {"hey", "now"};
    

    Although that's probably not too useful for you. Frankly its not hard to put them on two lines:

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

提交回复
热议问题