数组和类声明的几种方式
1个回答
展开全部
//数组的声明
//第一种
int[] arr1 = null;
arr1 = new int[3];
//第二种
int[] arr2 = new int[3];
//第三种
int[] arr3 = new int[3] { 1, 2, 3 };
//第四种 不设置数组的初始化大小,有数组元素确定
int[] arr4 = new int[] { 1, 2, 3 };
//这个是第四种的简化版
int[] arr5 = { 1, 2, 3 };
//类声明的几种方式
Person p1 = new Person();
p1.Name = "小明1";
p1.Age = 20;
Person p2 = new Person() {
Name = "小明2",
Age = 19
};
Person p3 = new Person{
Name = "小明3",
Age = 19
};
Person[] arr_p = new Person[] {
new Person {
Name = "小红",
Age = 18
},
new Person {
Name = "小黑",
Age = 19
}
};
//第一种
int[] arr1 = null;
arr1 = new int[3];
//第二种
int[] arr2 = new int[3];
//第三种
int[] arr3 = new int[3] { 1, 2, 3 };
//第四种 不设置数组的初始化大小,有数组元素确定
int[] arr4 = new int[] { 1, 2, 3 };
//这个是第四种的简化版
int[] arr5 = { 1, 2, 3 };
//类声明的几种方式
Person p1 = new Person();
p1.Name = "小明1";
p1.Age = 20;
Person p2 = new Person() {
Name = "小明2",
Age = 19
};
Person p3 = new Person{
Name = "小明3",
Age = 19
};
Person[] arr_p = new Person[] {
new Person {
Name = "小红",
Age = 18
},
new Person {
Name = "小黑",
Age = 19
}
};
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询