C# 解决不明确的引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14141043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resolving an ambiguous reference
提问by Sayse
I'm trying to create a manager class to use with my charting tool, the problem is the tool I use, uses the same names for both a 3d and 2d charts which is resulting in ambiguous reference when I try to add the 2d library.. any ideas how best to resolve this?
我正在尝试创建一个管理器类以与我的图表工具一起使用,问题在于我使用的工具对 3d 和 2d 图表使用相同的名称,这导致我在尝试添加 2d 库时引用不明确。 . 任何想法如何最好地解决这个问题?
For example,
例如,
using tool.2dChartLib;
using tool.3dChartLib;
BorderStyle is a member of both of these
BorderStyle 是这两者的成员
I've tried casting the areas where I use BorderStyle. I suppose it could work if i just reference tool
but then that would mean I'd have hundreds of tool.class
lines instead of class
我试过投射我使用 BorderStyle 的区域。我想如果我只是参考它可以工作,tool
但这意味着我会有数百tool.class
行而不是class
采纳答案by Adam Robinson
If the types with the same name exist in both namespaces, you have a couple of options:
如果两个命名空间中都存在同名的类型,您有几个选择:
1) If the number of types is small, create an alias for that type:
1)如果类型数量少,则为该类型创建一个别名:
using BorderStyle3d = tool.3dChartLib.BorderStyle;
2) If the number of types is large, you can create an alias for the namespace:
2)如果类型数量较多,可以为命名空间创建别名:
using t3d = tool.3dChartLib;
Then in your code...
然后在你的代码...
t3d.BorderStyle
回答by Tilak
Use namespace alias
使用命名空间别名
using twoDimensionLib = tool.2dChartLib;
using threeDimensionLib tool.3dChartLib;
回答by Sergey Berezovskiy
You can use full type names, or create aliases:
您可以使用完整的类型名称,或创建别名:
using 2dBorderStyle = tool.2dChartLib.BorderStyle;