构造函数: public int age;
public string name;
public char sex;
public double height;
public double weight;
public person()
{
age = 20;
name = "李四";
sex = '男';
height = 180;
weight = 80;
}----------------------------------------------------有参函数:
class Program
{
static void Main(string[] args)
{
person p = new person (20,"李四",'男');
Console.WriteLine(p.sex);
Console.ReadLine();
}
}
public class person // 定义person类
{
public int age;
public string name;
public char sex;
public double weight;
public double height; public person (int _age,string _name,char _sex)
{
this.age = _age;
this.name = _name;
this.sex = _sex;
}-------------------------------------------------------方法调用: class Program
{
static void Main(string[] args)
{ //实体化
person p = new person (20,"李四",'男');
Console.WriteLine(p.group());
Console.ReadLine();
}
}
public class person // 定义person类
{
public int age;
public string name;
public char sex;
public double weight;
public double height;
public person (int _age,string _name,char _sex)//有参函数
{
this.age = _age;
this.name = _name;
this.sex = _sex;
} public string group()
{
string mes = string.Format("大家好,我叫:{0},今年{1}",
this.name, this.age);
return mes;
}
---------------------------------------------------------构造函数:初始化对象;方法重载:方法名相同,参数表不同,返回类型可同,可不同!