简体   繁体   English

解决C#中的歧义引用

[英]Resolve ambiguous reference in C#

I am working on a WCF client where i have 2 service references.Both service references have a common method names.I have GetNames() in both of my service references.Since i have to instantiate based on the condition ,I am trying to do the following: 我在WCF客户端上工作,我有2个服务引用。两个服务引用都有一个通用的方法名称。两个服务引用中都有GetNames()。由于我必须根据条件进行实例化,因此我试图做下列:

IF Yes

Serviceclient1.GetNames name1= new Serviceclient1.GetNames();

Else

ServiceClient2.GetNames name2 =new Serviceclient1.GetNames();

But I am getting ambiguous reference even though i am referring to two different namesspaces ? 但是,即使我引用的是两个不同的命名空间,我也会得到不明确的引用?

I would be glad if some one can guide me here ? 如果有人可以指导我在这里我会很高兴?

You need to do one of the following: 您需要执行以下操作之一:

1) Fully qualify Serviceclient1 , as in: 1)完全合格的Serviceclient1 ,如:

var name1 = new Namespace.Serviceclient1.GetNames();

2) Add a using statement like the following: 2)添加using语句,如下所示:

using SomeAlias = Namespace.Serviceclient1;

Try aliasing your conflicting reference. 尝试给您有冲突的引用加上别名。

using ServiceCient2 = Namespace.Serviceclient1;

From MSDN, How to: Use the Global Namespace Alias 从MSDN, 如何:使用全局命名空间别名

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

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