static void InitAndPrint()
2{
3 int x = 7;
4 string s = "This is a string.";
5 double d = 99.99;
6 int[] numbers = new int[] { 0, 1, 2, 3, 4, 5, 6 };
7
8 Console.WriteLine("x: " + x);
9 Console.WriteLine("s: " + s);
10 Console.WriteLine("d: " + d);
11 Console.WriteLine("numbers: ");
12 foreach (int n in numbers) Console.WriteLine(n);//foreach时必须指定变量类型
13}
以上是3.0以下的版本
以下是3.0版本,支持var,变体型
static void InitAndPrint()
2 {
3 var x = 7;
4 var s = "This is a string.";
5 var d = 99.99;
6 var numbers = new int[] { 0, 1, 2, 3, 4, 5, 6 };
7
8 Console.WriteLine("x: " + x);
9 Console.WriteLine("s: " + s);
10 Console.WriteLine("d: " + d);
11 Console.WriteLine("numbers: ");
12 foreach (int n in numbers) Console.WriteLine(n);
13 }
2{
3 int x = 7;
4 string s = "This is a string.";
5 double d = 99.99;
6 int[] numbers = new int[] { 0, 1, 2, 3, 4, 5, 6 };
7
8 Console.WriteLine("x: " + x);
9 Console.WriteLine("s: " + s);
10 Console.WriteLine("d: " + d);
11 Console.WriteLine("numbers: ");
12 foreach (int n in numbers) Console.WriteLine(n);//foreach时必须指定变量类型
13}
以上是3.0以下的版本
以下是3.0版本,支持var,变体型
static void InitAndPrint()
2 {
3 var x = 7;
4 var s = "This is a string.";
5 var d = 99.99;
6 var numbers = new int[] { 0, 1, 2, 3, 4, 5, 6 };
7
8 Console.WriteLine("x: " + x);
9 Console.WriteLine("s: " + s);
10 Console.WriteLine("d: " + d);
11 Console.WriteLine("numbers: ");
12 foreach (int n in numbers) Console.WriteLine(n);
13 }