namespace Class和interface
{
class Program
{
static void Main(string[] args)
{
Person person = new Person();
Console.WriteLine(person.GetAge(1));
//调用时使用实例化的对象调用
Console.WriteLine(Person.GetFive());
//static方法使用时直接使用"类名.方法"调用,不能使用实例化后的对象调用
//静态的方法或字段是存储在class类上的,不能实例化
}
}
class Person
{ //可以包含字段、方法、属性
int age;
public int GetAge(int Mage)
{
this.age=Mage;//this表示当前class实例化后的对象,因为在自己的class中可以省略this不写
return age;
}
public static int GetFive()
{
return 5;
}
}
}
C#类中的属性
public int Age
{
get //get从旧内存中取值
{
return age + 10;
}