Assign the same value to multiple variables in a single statement

Table of contents

No heading

No headings in the article.

You might be seen this statement previously where we assign a single value to multiple variables,

int num1, num2, num3;

num1 = num2 = num3 = 5;

But within C# we can assign multiples values to multiple variables using the statement

var (a, b, c) = (1, 2, 3);

By doing this, we have got

a = 1, b = 2, c = 3