代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NewConApp
{
class Program
{
static void Main(string[] args)
{
int[,] nums1 = { {1,2,3},{4,5,6} }; //声明一个3列,2行的多维数组
Console.WriteLine(nums1.Length); //结果为6
Console.WriteLine(nums1[0,2]); //结果为3
int[][] num2 = {
new int[] { 1,2,3,4,5 },
new int[] { 2 },
new int[] { 4,5 },
new int[] { 2,3,9,5 }
}; //声明一个元素类型为Int 数组的交错数组
Console.WriteLine(num2.Length); //结果为4
Console.WriteLine(num2[3][2]); //结果为9
int[] num3; //除非声明数组后,马上初始化,否则,必须用 new int[3]
num3 = new int[3] { 13, 16, 19 }; // 错误写法: num3 = { 13,16,19 }; 定义好数组后在初始化数值时需要new关键字。
//错误:int[] nums=new int[3]{};
//正确:int[] nums=new int[3]{1,2,3}; 初始化变量时如果指定了数组大小必须初始化数据,同时初始化的数据数量和指定的数组长度必须一样。
string script1 = @"
<script type='text/javascript'>
alert('Hello World');
</script>
";
Console.WriteLine(script1);
char a = 'a'; //97
char f = 'f'; //102
Console.WriteLine("f-a=" + (f - a)); //结果为5
}
}
}
谢谢浏览!
浙公网安备 33010602011771号