在 C# 中,您可以继承多少个类?
当你写:
using System.Web.UI;
这被认为是从一个类继承的吗?
使用指令:
using X.Y.Z;
仅表示如果标识符不在本地命名空间中,则X.Y.Z
还将在命名空间中搜索该标识符。这使您可以拥有一些更简洁的代码,例如,System.IO.Path.Combine()
如果您有. 我不相信您可以拥有using System.IO.Path
多少个语句。using
C# 不允许多重继承——你只能从一个类继承。但是,您可以实现任意数量的接口。
您只能从一个类继承。
编写“使用 System.Web.UI”与继承无关。该语句仅表示您要“使用”命名空间 System.Web.UI 中的类,以便您可以直接编写类名,而不是让它以命名空间名作为前缀。
不。
using
makes externally defined classes visibleclass Cat : Animal
defines a class Pet
that derives (inherits) from Animal
C#, unlike C++, does not support multiple inheritance, therefore you can only derive it from one class (However, you can implement any number of interfaces)
I'd like to add an addendum to the answer given by Jen. It's correct to say that C# doesn't support multiple inheritance, but it can be useful to know that you can implement multiple inheritance in .NET by ignoring the CLS (the Command Language Subsystem). It's nasty work, and involves you rolling your own vtables, but it is possible.