.Net partial class and virtual
2012-10-04 16:08
357 查看
.net 자바랑 틀린점
1. partial class 쪼개는 클래스 ...
2.virtual 상속 받게 하는 키워드 (---mvc3 에서 Entity에 넣지않으면 오류생기는 키워드)
====== 분할점 ======
1. partial
클래스(Class)는 경우에 따라 덩치가 커지는 경우가 있습니다. 사실 클래스가 너무 커지면 관리하기가 어려울 수도 있는데 이런 경우를 대비해 같은 클래스를 여러파일로 분리할 수 있습니다. 예를 들어 한쪽에는 필드(Field)만을 담고 다른 한쪽에는 메소드(Method)만을 담아놓은 식으로 말이죠.(단 이 기능은 .NET 1.x에서는 지원하지 않습니다.)
클래스를 분리하는 방법은 간단합니다. 그저 클래스이름 앞에 Partial이라는 키워드(Keyword)만 쓰면 끝입니다.
![](http://cfile5.uf.tistory.com/image/156C76484D64552C01D9D1)
▶C#
![](http://cfile5.uf.tistory.com/image/117E574D4D64552C3095C0)
2. virtual
class Shape
{
public virtual void Draw()
{
Console.WriteLine("Shape.Draw") ;
}
}
class Rectangle
: Shape
{
public override void Draw()
{
Console.WriteLine("Rectangle.Draw");
}
}
1. partial class 쪼개는 클래스 ...
2.virtual 상속 받게 하는 키워드 (---mvc3 에서 Entity에 넣지않으면 오류생기는 키워드)
====== 분할점 ======
1. partial
클래스(Class)는 경우에 따라 덩치가 커지는 경우가 있습니다. 사실 클래스가 너무 커지면 관리하기가 어려울 수도 있는데 이런 경우를 대비해 같은 클래스를 여러파일로 분리할 수 있습니다. 예를 들어 한쪽에는 필드(Field)만을 담고 다른 한쪽에는 메소드(Method)만을 담아놓은 식으로 말이죠.(단 이 기능은 .NET 1.x에서는 지원하지 않습니다.)
클래스를 분리하는 방법은 간단합니다. 그저 클래스이름 앞에 Partial이라는 키워드(Keyword)만 쓰면 끝입니다.
▶C#
2. virtual
class Shape
{
public virtual void Draw()
{
Console.WriteLine("Shape.Draw") ;
}
}
class Rectangle
: Shape
{
public override void Draw()
{
Console.WriteLine("Rectangle.Draw");
}
}
相关文章推荐
- virtual function and abstract class
- .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numer
- 从Atlas到Microsoft ASP.NET AJAX(3) - Class and Type Definition, Reflection APIs
- 从Atlas到Microsoft ASP.NET AJAX(3) - Class and Type Definition, Reflection APIs
- ASP.NET中Partial Class的使用
- How to create aligned partitions in Linux for use with NetApp LUNs, VMDKs, VHDs and other virtual di
- 从Atlas到Microsoft ASP.NET AJAX(3) - Class and Type Definition, Reflection APIs
- ADO.NET 2.0 利用 partial class 擴充 TableAdapter method
- Partial mock local private method or public method in the class and suppress static initial block
- In .net Class and Struct
- Part 61 to 63 Talking about partial class and partial method in C#
- The longest class name in Java and .NET Framework
- Where Are ClassWizard and WizardBar in Visual C++ .NET?[msdn]
- Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy! 转
- Runtime class and object in .net
- [C++] Pure Virtual Function and Abstract Class
- WinForm C#: Simple Runtime Control ReSizing and Dragging & Moving Class
- VB.NET and C# 语法比较手册
- 项目管理实践【三】每日构建【Daily Build Using CruiseControl.NET and MSBuild】
- java class and object initialization--java类和对象初始化