->인스턴스를 만들지 않고도 사용 가능하다. ex) MyClass.StaticMethod();
Class Myclass
{
int a, b, c;
public MyClass()
{
this.a = 1;
}
public MyClass(int b) : this()
{
this.b = b;
}
public MyClass(int b, int c) : This(b)
{
this.c = c;
}
}
if(mammal is Dog) //dog이 아니라면 false
{
dog = (Dog)mammal;
dog.Bark;
}
Cat cat = mamal2 as Cat; // as로 형변환하여 참조
if(cat != null) // as 실패시 null
{
cat.Meow();
}
new를 사용하여 기반 클래스에서 구현된 버전의 메소드를 감추고 파생 클래스에서 구현된 메소드만 보이도록 할 수 있다.
calss Derived : Base
{
public new void MyMethod()
{
Console.WriteLine("Derived.MyMethod()");
}
}
private readonly int min
namespace MyExtension
{
public static class IntegerExtension
{
public static int Power(this int myInt, int exponent)
{
int result = myInt;
for ( int i=1; i<exponent; i++ )
{
result = result * myInt;
}
}
}
}
int a =2;
Console.WriteLine(a.Power(2));