* 关于无参构造器
* 当类中没有任何构造器时,编译器会默认添加一个无参构造器
* 但是,一旦类中有构造器之后,编译器就不会再添加默认无参构造 器
*
* 一般设计类时,无论如何,手动添加无参构造器
* @author Administrator
*在一个类中,不能存在两个参数列表相同的构造器(参数列表不同)
* 参数的个数不同:
* 1.参数的个数不同
* 2.参数的类型不同
* 3.参数的类型不同,并且顺序不同
using System;
namespace ConsoleApp2
{
class dome
{
static void Main(string[] args)
{
st[] students = new st[30];
st stu1 = new st();
stu1.Name = "元芳";
stu1.Age = 18;
stu1.ClassName = "s1";
stu1.StuNo = "2019001";
st stu2 = new st();
stu2.Name = "狄仁杰";
stu2.Age = 19;
stu2.ClassName = "s2";
stu2.StuNo = "2019002";
st stu3 = new st("2019003", "李白", 19, "s3");
students[0] = stu1;
students[1] = stu2;
students[2] = stu3;
for (int i = 0; i < students.Length; i++)
{
st stu = students[i];
if (stu != null)
Console.WriteLine($"姓名:{stu.Name},年龄{stu.Age},班级{stu.ClassName},编号{stu.StuNo}");
}
}
}
}
类
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp2
{
public class st
{
public st()
{
}
public st(string stuNo,string name,int age,string className)
{
this.StuNo = stuNo;
this.Name = name;
this.Age = age;
this.ClassName = className;
}
public string StuNo;
public string Name;
public int Age;
public string ClassName;
}
}