public class Person
{
public string name;
public int age;
public Person()
{
this.name = "unknown";
this.age = 99;
}
public Person(string _name,int _age)
{
this.name = _name;
this.age = _age;
}
}
class Program
{
static void Main(string[] args)
{
Person someone = new Person();
Console.WriteLine(someone.name+" "+someone.age.ToString());
Person another = new Person("Mike",20);
Console.WriteLine(another.name + " " + another.age.ToString()); }
}
复习了一下构造函数,一篇不错的文章“C#中构造函数和析构函数的用法”,以下是链接http://www.7880.com/Info/Article-e64ff60.html其实书本上学的概念,好像不难懂,但要真的编程应用一下才算真正掌握。如果不是碰到这道练习题,我都不知道一个类可以有多个构造函数,真是惭愧。
{
public string name;
public int age;
public Person()
{
this.name = "unknown";
this.age = 99;
}
public Person(string _name,int _age)
{
this.name = _name;
this.age = _age;
}
}
class Program
{
static void Main(string[] args)
{
Person someone = new Person();
Console.WriteLine(someone.name+" "+someone.age.ToString());
Person another = new Person("Mike",20);
Console.WriteLine(another.name + " " + another.age.ToString()); }
}
复习了一下构造函数,一篇不错的文章“C#中构造函数和析构函数的用法”,以下是链接http://www.7880.com/Info/Article-e64ff60.html其实书本上学的概念,好像不难懂,但要真的编程应用一下才算真正掌握。如果不是碰到这道练习题,我都不知道一个类可以有多个构造函数,真是惭愧。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货