如何在C#中将多个值分配给同一变量?
要将多个值设置为同一变量,请在C#中使用数组。假设不是采用5个变量,而是使用数组在单个变量中设置这5个变量。
以下是使用字符串数组将三个值设置为单个变量的示例-
string[] arr = new string[3];
现在让我们初始化它-
string[] arr = new string[3] {"one", "two", "three"};以下是完整的示例-
示例
using System;
public class Demo {
static void Main(string[] args) {
string[] arr = new string[3] {"one", "two", "three"};
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine("Values: " + arr[i]);
}
Console.ReadKey();
}
}输出结果
Values: one Values: two Values: three
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便