c#第三章

来源:互联网 发布:mac os x 10.7 .2 iso 编辑:程序博客网 时间:2024/06/01 07:33

1.opp三大支柱封装(Encapsulation),多态(Polymorphism),继承(Inheritance)


2.

默认情况下,类声明为内部的,即只有当前项目中的代码才能访问它

internal class MYclass2 { }

类是公共的,可由其他中的项目访问

public class MYclass { }

内部类(internal)可以继承于公共类(public),反之不行


3.

突然想到c++中的运算符重载

priority_queue<pii,vector<pii>,greater<pii> >que;

如果用priority_queue<pii>que,后面的参数编译器自动填好了



4.

如果没有写构造函数,编译器自动创建并赋值


Type

Default value

numeric(int,long,etc.)

0

bool

false

char

'\0' (null)

enum

0

reference

null


5.

静态函数:

Static method cannot access anon-static member variable.
因为没法确定非静态函数是否被实例化
Guaranteed that the stati cconstructor will run before any instance of the class is created.
静态类是密封的(sealed)不能从它派生(derive)类型。


6.
    class myclass    {        private int myProperty;        /*public int myproperty        {            get { return this.myProperty; }            set { this.myProperty = value; }        }*/        public int myproperty { get; set; }    }    class Program    {                static void Main(string[] args)        {            myclass cur = new myclass();            cur.myproperty = 1;            Console.WriteLine(cur.myproperty);        }    }


7.

readonly成员只能在下面的两种情况下被赋值:

1. Static constructor

2. A variable initializer



0 0