码迷,mamicode.com
首页 > Windows程序 > 详细

C#复习中...

时间:2015-05-26 22:51:02      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

CIL: Common Intermediate Language 公共中间语言
CLR: Common Language Runtime 公共语言运行库
Creation of New Types is the essence(核心)of OOP.
Type(类型) is defined by class and object(对象) is the instance(实例) of class.
赋值语句: 值域大的变量 = 值域小的变量;
占位符
foreach循环
Three pillars(3大支柱) of OOP Encapsulation(封装) Polymorphism(多态) Inheritance(继承)
declare optional arguments e.g int foo(int a double b=6.5){ ... }
Constructor:No return type Declared as Public accept arguments
Using Static Members: static
You access a static member through the name of the class/object in which it is declared.
The members of a class can be either instance members or static members.
Static methods don’t have a this reference.
Static method can not access a non-static member variable.
ref and out(按引用传参)
out 可以对未赋初值的参数进行赋值
Overloading(重载) Methods & Constructors 使用同一个“方法名”提供不同功能。
Overloading vs Overriding
Overloading is when you have multiple methods in the same scope, with the same name but different signatures
Overloading (Compile Time Polymorphism):: Functions with same name and different parameters
Overriding is a principle that allows you to change the functionality of a method in a child class.
Overriding (Run Time Polymorphism): Functions in the extended class with same name and same parameters as
in the base class, but with different behaviors.
ncapsulating(封装) Data with Properties(属性)
Properties{get ; set ;}
override :
public class ListBox : Control { public new virtual void Sort() {...}
Use new to indicate that it is not an override of the base method in Control class.
public class ListBox : Control { public override void Sort() {...}
Use override to indicate that it does want to override of the base method in Control class.
e.g
class A { public virtual void Movie() { Console.WriteLine("MikiMouse"); } }
class B : A { public override void Movie () { Console.WriteLine("DisneyMovie"); } }
class C : B { public new virtual void Movie () { Console.WriteLine("Snow White"); } }
class D : C { public override void Movie () { Console.WriteLine("Seven Dwarfs "); } }
class TestMe{ static void Main() {
A objA = new D();
A objB = new B();
C objC = new D();
A objD = new A();
objA.Movie();
objB.Movie ();
objC.Movie ();
objD.Movie(); } }
Abstract Classes
To require subclasses to implement a method of their base, you need to designate that method as abstract.
Once you declare a method to be abstract, you prohibit the creation of any instances of that class.
Sealed 类(完全不允许派生), 防止偶然继承。与Abstract类(用来派生)正相反。
C# insists that the both of logical operator pairs should be overloaded. Otherwise , It generates a Compile Error.
等于操作符(==)重载(overload)时,同时也应该覆盖 (Override) Object提供的虚方法Equals(),
让它也采用重载的(==)进行操作。当然(!=)也要重载。
关于类型转换,当我们将小范围值转换为大范围值或者是转换会使数的精度有损失的时候需要显式转换
implicit 隐式 explicit 显式
Interfaces vs Abstract Classes
一个类/接口可以继承一个类 一个类/接口可以继承多个接口
当继承自抽象类时,选择性的override函数,当继承自接口时,必须实现所有函数
注意:接口中的所有函数只需要写签名,且不能用access-modifie

C#复习中...

标签:

原文地址:http://www.cnblogs.com/ljc825/p/4531883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!