using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 类对象赋初值,数组赋初值的区别
{
class Student
{
public string Name { get; set; }
public string Language { get; set; }
public string Position { get; set; }
public Student()
{
}
}
class Program
{
static void Main(string[] args)
{
//创建Student类的实例,并给类属性赋初值
Student stt = new Student() { Name = "钱掌柜", Language = "数学", Position = "七侠镇" };
//创建一个Student类型的数组,里面放置的是Student对象
Student[] stu=new Student[]
{
new Student{Name="张三",Language="c#",Position="Leader"},
new Student {Name="李四",Language="c#",Position="Coder"},
new Student{Name="王五",Language="java",Position="Coder"}
};
Console.ReadKey();
}
}
}
数组赋值
最新推荐文章于 2024-08-21 11:22:10 发布