WDUK
WDUK

Reputation: 1524

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.

Upvotes: 2

Views: 565

Answers (2)

devsmn
devsmn

Reputation: 1040

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
        }
    }
}

Upvotes: 2

Rafalon
Rafalon

Reputation: 4515

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.

Upvotes: 6

Related Questions