标签:new pre int main ons 值类型 console over this
一、之值类型与引用类型
public static void Main(string[] args)
{
int age = 10;//值类型在内存中开辟一块区域存放
object age1 = age;//引用类型存的是地址 此时指向age的初始地址
age += 1;//age重新开辟新的区域 此时为11,
Console.WriteLine("fist="+age1);//指向老的区域 值为10;
int age2=(int)age1;//引用类型转化值类型 为10;
Console.WriteLine("test="+age2);
age2 += 1;
Console.WriteLine("secend="+age);
Console.ReadKey();
}
输出结果 10 10 11
二、之继承重写
public class Program
{
public static void Main(string[] args)
{
Employee yee = new Employee();
Console.ReadKey();
}
}
class Person
{
protected int age = 10;
public Person()
{
this.Output();
}
public virtual void Output()
{
Console.WriteLine("Person"+this.age);
}
}
class Employee : Person
{
public Employee() : base()
{
base.age = 20;
}
public override void Output()
{
Console.WriteLine("Employee"+base.age);
}
}
输出结果 10
标签:new pre int main ons 值类型 console over this
原文地址:http://www.cnblogs.com/eric-gms/p/6416275.html