简体   繁体   中英

Two namespaces with the same object name

I have two namespaces:

System.Numerics and UnityEngine

Both have the type 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 ?

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.

If all you need from System.Numerics is Complex , then:

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

At the top of your file, without 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. 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
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM