publicclass Test1
{
private int _age=10;
public int Age
{
get { return _age; }
set { _age = value; }
}
public virtual void Output1(string name)
{
name ="Test1";
Console.Write("Test1.Output1 :Name is "+ name);
}
public virtual void Output2(ref stringrefname)
{
refname = "Test1";
Console.Write("Test1.Output2 :Name is " + refname);
}
}
public class Test2:Test1
{
private int _age=20;
public override void Output1(stringname)
{
name ="Test2";
Console.Write("Test2.Output1 :Name is "+ name);
}
public new void Output2(ref stringrefname)
{
refname = "Test2";
Console.Write("Test2.Output2 :Name is " + refname);
}
}
string name = "Name";
string refname = "RefName";
Test1 t1 = new Test2();
t1.Output1(name); //输出1?
t1.Output2(ref refname); // 输出2?
Console.Write(name); // 输出3?
Console.Write(refname); // 输出4?
Test2 t2 = new Test2();
Console.Write(t2.Age.ToString()); //输出5以及是否装箱?
t2.Output2(ref refname); //输出6
慕姐8265434