有多少类可以从C#继承? [英] How many classes can you inherit from in C#?
问题描述
有多少类可以从 .NET ?
有几个后端C#文件,我想和大家分享单独的静态方法,但是他们都在不同的班级。有没有办法继承多个类?
There are several backend C# files that I would like to share separate static methods, but they are all in different classes. Is there a way to inherit multiple classes?
举例code会大大AP preciated。
Example code would be much appreciated.
推荐答案
C#不支持多重继承(指一个类从多个类继承)。你可以,但是,实现在一个类多个接口。
C# does not support multiple inheritance (meaning a single class inherits from multiple classes). You can, however, implement multiple interfaces in a single class.
至于链一起继承类,没有每本身的限制。只要记住的,你会介绍给你的系统的复杂性。当使用继承,确保你在是的场景使用它。一个猎豹是动物。马自达是汽车。否则,你的产业紧密结合与变得更加困难,以保持设计你的类。
As far as chaining together inherited classes, there isn't a limit per-se. Just keep in mind the complexity you will introduce to your system. When using inheritance, make sure you are using it in a "is a" scenario. A cheeta is an animal. A mazda is a car. Otherwise, your inheritance tightly couples your classes with a design that becomes much more difficult to maintain.
如果他们是静态的效用的方法,只需直接调用它们不继承。除非这些方法都属于正在创建的实体,你不应该使用继承。
If they are static "utility" methods, just invoke them directly without inheriting. Unless those methods belong to the entity you are creating, you should not use inheritance.
这篇关于有多少类可以从C#继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!