2 回答

TA貢獻1803條經驗 獲得超6個贊
C# 允許,單個語句可以分配多個局部變量
int i = 5, y = 10, x = 100;
Console.WriteLine("{0} {1} {2}", i, y, x);
const string s = "dot", a = "net", m = "perls";
Console.WriteLine("{0} {1} {2}", s, a, m);
int j = 1, k, z;
Console.WriteLine(j);
k = z = 0; // Initialize the others
Console.WriteLine("{0} {1}", k, z);

TA貢獻1866條經驗 獲得超5個贊
這幾乎與您將要獲得的一樣接近。C# 不允許你想要的。但是,如果您想要一種簡單的方法來粘貼變量值數組,這是 C# 中最好的方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int[] values = { 1, 2, 7, 8, 42 };
int a = values[0];
int b = values[1];
int c = values[2];
int d = values[3];
int e = values[4];
Console.WriteLine($"a={a}, b=, c={c}, d=eyu6jru, e={e}");
}
}
}
- 2 回答
- 0 關注
- 157 瀏覽
添加回答
舉報