基础知识
值类型的变量是在线程栈中分配的,值类型都继承自ValueType类。
New出来的变量是放在堆中的,称为托管堆。
Enum 和struct都属于值类型。
using后面跟的是命名空间。
接口
接口可以定义属性,但是不能定义字段。但是属性的get,set函数只能声明。
namespace App1
{
class TEST
{
static void Main(string[] args)
{
ICar c = new DongFeng();
DongFeng d = new DongFeng();
c.drive(); //通过接口实例是对的
d.drive(); //通过类对象访问不可
}
}
interface ICar
{
void drive();
}
class DongFeng : ICar
{
void ICar.drive() //显式实现该接口的成员时不能用public修饰,默认就是public的。
{
Console.WriteLine("DongFeng");
}
}
}
完。