我的第一课
时间:2011-05-05 来源:fuck you
using System;
using System.Threading;
using System.IO;
using System.Text;
using System.Reflection;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
//step 1
Test i = new Test();
i.Age = 5;
i.Name = "cp";
Test j = i.CopySelf();
j.Name = "rcc";
j.Age = 4;
Console.WriteLine(i.Age == j.Age); //false
Console.WriteLine(i.Name == j.Name); //false
//step 2
int ii = 55;
Test k = new Test(); //实例化
k.Age = 18; //赋值
k.Name = "xd"; //赋值
Magic(k, ii); //调用静态方法
Console.WriteLine(k.ToString()); //name:xd;age:18 利用了重写方法
Console.WriteLine(ii); //55
//step 3
Test l = new Test();
Magic(l);
Console.WriteLine(l.ToString()); //name:hz;age:0 ?????
}
static void Magic(Test t, int i) //静态方法
{
t = new Test();
t.Name = "xyp";
t.Age = 109;
i = 99;
}
static void Magic(Test t) //重写Magic方法
{
t.Name = "hz";
t = new Test();
t.Name = "wq";
}
}
class Test
{
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
public Test CopySelf() //返回 Test格式
{
return this.MemberwiseClone() as Test; //创建 Test的副本
}
public override string ToString() //对ToString重写
{
return string.Format("name:{0};age:{1}", this.Name, this.Age);
}
}
}
请不运行尝试写出输出结果