[英]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.