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={b}, c={c}, d={d}, e={e}");
}
}
}
- 2 回答
- 0 关注
- 67 浏览
添加回答
举报