sealed keyword.
base keyword.
protected keyword.
Contain/delegate model(has-a relationship):
Class A
{
}
Partial class B
{
protected A a=new A();
}
public partial class B
{
protected A a=new A();
public A AProperty
{
set{ return a; }
get{ a=value; }
}
}
Nested type definition:
public class OuterClass
{
public class PublicInnerClass(){}
private class PrivateInnerClass(){}
}
virtual and override keyword
Class B: A
{
public override sealed void GetPropertyX()
{
...
}
}
Abstract class(cannot new)
Abstract method only can define in abstract class.
Member shadowing:
Class A
{
public string shapeName;
public void Draw()
{
//doing something that we cannot modify
}
}
Class B: A
{
protected new string shapeName;
public new void Draw()
{
//doing what we want
}
}
Base/derive converting rule:
Object o=new A();// "is-a" relationship
Baseclass bc=new Derivedclass();
"as" and "is" keyword
"as": Convert when running,
object is not compatible will return null,
Object is null will throw NullReferenceException;
"is": not compatible will return false;