C#之数组定义

来源:互联网 发布:qq群发信息软件 编辑:程序博客网 时间:2024/05/16 15:20
c#数组定义与以往学的c和c++有点区别,而且new之后不用delete
using System;using System.Text;namespace Excise1{    public class Program    {        public static void Main(string[] args)        {            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);            //与c不同,c#不能在定义数组的时候直接在方括号里指定大小            /*             如 string array[5];  错误                string []array;  错误                int []array=new int[5]{1,2,3}; 错误 ,数组初始值与数组长度不一             */            string []array;            array = new string[3];            string []array1 = new string[3] { "yes", "no", "no sure" }; //初始化            string[] array2 = new string[] { "yes", "no", "no sure" };  //初始化省略长度            string[] array3 ={ "yes", "no", "no sure" };//省略new            Console.ReadKey();         }    }}
0 0
原创粉丝点击