问题
I know : indicates inheritance in C#;
but what does it mean when the same identifier is on either side?
Eg
class GameObject : GameObject {
回答1:
It does not work, because Visual Studio will throw a 'cyclic dependency' error, because, when you think about it, GameObject inherits from GameObject which inherits from GameObject which inherits from... In other words, this is impossible, and so means nothing (except, like Neil mentioned in the comments, a compiler error).
回答2:
Or this is Unicode
class GameObject
{
}
class GameObjеct : GameObject
{
}
回答3:
The syntax you provided is legal if base class is declared in a different namespace You need, however, use namespaces to resolve naming conflicts
Example
namespace A
{
class GameObject
{
}
}
namespace B
{
class GameObject: A.GameObject
{
}
}
Another possible scenario involves generics, which allow class name overload. The following will also compile:
class GameObject
{
}
class GameObject<T> : GameObject
{
}
class GameObject<T, T> : GameObject<T>
{
}
来源:https://stackoverflow.com/questions/7116614/c-sharp-inheritance-same-identifier-on-either-side-of