定义一个student类,成员变量是name和age,定义一个无参的构造方法和一个两个参数的构造方法,在测试类中分别调用这两个构造方法产生对象,并输出两个对象的name和age的值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q1063732
{
class student
{
public string name;
public int age;
public student(string n, int a) { name = n; age = a; }
public student() : this("noname", 0) { }
public override string ToString()
{
return string.Format("name={0},age={1}",name,age);
}
}
class Program
{
static void Main(string[] args)
{
student s1 = new student();
Console.WriteLine(s1);
student s2 = new student("a", 20);
Console.WriteLine(s2);
}
}
}