use*_*618 7 c# inheritance modeling
我必须为应用程序构建新模型,而不是更好的方法:
使用继承或使用enum作为对象类型:
例如 :
图书
class Book
{
public string Name {get;set;}
public string Author {get;set;}
public int NumberOfPages {get;set;}
}
public class Encyclopedie:Book
{
}
public class Novel:Book
{
}
Run Code Online (Sandbox Code Playgroud)
或更好地使用:
class Book
{
public BookType Type {get;set;}
public string Name {get;set;}
public string Author {get;set;}
public int NumberOfPages {get;set;}
}
public enum BookType
{
Encyclopedie = 0,
Novel = 1,
...
}
Run Code Online (Sandbox Code Playgroud)