简体   繁体   English

具有相同对象名称的两个名称空间

[英]Two namespaces with the same object name

I have two namespaces: 我有两个名称空间:

System.Numerics and UnityEngine System.Numerics和UnityEngine

Both have the type Vector3 . 两者的类型Vector3

So now when ever i want to use it i have to declare which namespace before it. 因此,现在无论何时我想使用它,我都必须在它之前声明哪个名称空间。 Like this: 像这样:

protected struct CVN
{
    public Complex h;
    public UnityEngine.Vector2 d;
    public UnityEngine.Vector3 n;
}

Is there any way to define that i only want Vector3 from one namespace so i don't have to always type NameSpaceHere.Vector3 every single time ? 有什么方法可以定义我只希望从一个名称空间获取Vector3 ,这样我就不必每次都总是键入NameSpaceHere.Vector3

Or am i stuck with the tedious nature of stating the namespace every time. 还是我坚持每次声明名称空间的乏味本质。 Especially since i only need the Complex type from Numerics its quite annoying. 特别是因为我只需要Numerics的Complex类型,这很烦人。

If all you need from System.Numerics is Complex , then: 如果您从System.Numerics需要的全部是Complex ,则:

using UnityEngine;
using Complex = System.Numerics.Complex;

At the top of your file, without using System.Numerics; 在文件顶部,不using System.Numerics; should do it. 应该这样做。 This is an alias . 这是一个别名

You can wrap the using directive of the wanted class in the namespace of your current class rather than putting it outside. 您可以将所需类的using指令包装在当前类的名称空间中,而不是将其放在外面。 Consider this example 考虑这个例子

namespace System.Numerics
{
    class MyClass
    {
    }
}
namespace UnityEngine
{
    class MyClass
    {
    }
}
using System.Numeric;

namespace ConsoleApplication24
{
    using UnityEngine; // inside the namespace
    class Program
    {
        static void Main(string[] args)
        {
            MyClass xx = new MyClass(); // from UnitEngine instead of System.Numeric
        }
    }
}

暂无
暂无

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

相关问题 C# 命名空间:在两个具有相同名称的相同命名空间中调用方法 - C# namespaces: Calling a method in two identical namespaces with same name c# 两个同名的命名空间 - c# two namespaces with the same name 如何选择具有相同名称的两个名称空间之一 - How to select one of two namespaces with the same name 如何处理具有相同名称的两个类的MVC DisplayTemplates(不同的命名空间) - How to handle MVC DisplayTemplates for two classes with the same name (different namespaces) 实体框架代码优先 - 两个具有相同名称但位于不同名称空间的实体 - Entity Framework Code First - two entities with same name but in different namespaces NHibernate DuplicateMappingException 当两个类具有相同的名称但不同的命名空间时 - NHibernate DuplicateMappingException when two classes have the same name but different namespaces 同一类的两个名称空间 - Two namespaces of the same class 使用城堡ActiveRecord,当两个类具有相同的名称但名称空间不同时,我得到了NHibernate DuplicateMappingException - Using Castle ActiveRecord, I get an NHibernate DuplicateMappingException when two classes have the same name but different namespaces 为什么在映射具有相同名称但不同名称空间的类的对象图时,XmlSerializer无法初始化? - Why is XmlSerializer failing to initialize when mapping the object graph of classes with the same name, but different namespaces? 如何在不同的命名空间中处理相同的类名? - How to handle same class name in different namespaces?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM