简体   繁体   English

两个类同名时如何设置默认类

[英]How to set the default class when two classes have the same name

If I have two namespaces eg如果我有两个命名空间,例如

using Code1.Dog;
using Code2.Cat;

and both namespaces have a class called "Legs", how I would i set the default one that is used, without writing a full name such as Code1.Dog.Legs?并且两个命名空间都有一个名为“Legs”的类,我将如何设置使用的默认类,而无需编写诸如 Code1.Dog.Legs 之类的全名?

In an ASP.NET controller I have a class called "User" but whenever I write it, it uses the default class in "System.Security.Principle".在 ASP.NET 控制器中,我有一个名为“User”的类,但是每当我编写它时,它都会使用“System.Security.Principle”中的默认类。 Would like to use my own class called "User" without using the full naming scheme eg "MyNamespace.User".想使用我自己的名为“User”的类而不使用完整的命名方案,例如“MyNamespace.User”。 How would I achieve this?我将如何实现这一目标? There is no way to not include the original class "System.Security.Principle".没有办法不包括原始类“System.Security.Principle”。

When you have classes with the same simple names, you must refer to them by their fully qualified class names.当您有具有相同简单名称的类时,您必须通过它们的完全限定类名称来引用它们。

That's the way even you can understand your code better too.这也是您可以更好地理解代码的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NHibernate DuplicateMappingException 当两个类具有相同的名称但不同的命名空间时 - NHibernate DuplicateMappingException when two classes have the same name but different namespaces 使用城堡ActiveRecord,当两个类具有相同的名称但名称空间不同时,我得到了NHibernate DuplicateMappingException - Using Castle ActiveRecord, I get an NHibernate DuplicateMappingException when two classes have the same name but different namespaces 两个包在同一个命名空间内具有相同的类名。 如何具体使用每个类? - Two packages have the same class name inside the same namespace. How to specifically use each class? 当所有子类都具有相同的基类(包括新类)时,如何继承多个子类? - How to inherit multiple partial classes when all have the same base class (including the new class)? 如何使用默认和用户配置的两个具有相同设置名称的setting.settings文件 - How to have two setting.settings file with the same setting name for default and user config 如何将具有相同名称的两个json属性转换为同一类中的属性 - How to convert two json properties that have same name into properties in same class 当类和命名空间同名时区分类和命名空间 - Differentiating class and namespace when class and namespace have the same name XML Serialization 格式需要非常具体,如何序列化与父类同名的子类? - XML Serialization format needs to be very specific, how do you serialize child classes that have the same name as their parent class? 如何让两个类引用相同的对象列表? - How to have two classes with references to the same list of objects? Java模板,如何使用两个具有相同名称和不同类型的类 - Java Templates, how to use two classes with the same name and different types
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM