C#: Assign same value to multiple variables in single statement

后端 未结 11 1225
甜味超标
甜味超标 2020-12-01 00:13

Is there any way (just out of curiosity because I came across multiple same-value assignments to multiple variables today) in C# to assign one value to multiple variables at

相关标签:
11条回答
  • 2020-12-01 00:36
    int num1=5,num2=5
    

    Declaring and assigning variables in the same statement.

    0 讨论(0)
  • 2020-12-01 00:36

    Something like this.

    num1 = num2 = 5
    
    0 讨论(0)
  • 2020-12-01 00:39

    It is simple.

    int num1,num2;
    num1 = num2 = 5;
    
    0 讨论(0)
  • 2020-12-01 00:41

    Try this:

    num1 = num2 = 5;
    

    Note that this won't work in VB.

    0 讨论(0)
  • 2020-12-01 00:41

    Your example would be:

    int num1 = 1;
    int num2 = 1;
    
    num1 = num2 = 5;
    
    0 讨论(0)
提交回复
热议问题