为两种服务类型使用相同的变量名称... [英] using same variable name for two service type...

查看:98
本文介绍了为两种服务类型使用相同的变量名称...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用两个服务,当我使用客户端Web服务时,即在生产模式和一个本地Web服务,当我的程序在测试模式下运行时,我的问题是,我想使用单个变量名称两种服务类型,并希望在运行时决定使用哪种服务类型,基于模式即生产模式或测试模式,但我得到以下错误

 < span class =code-keyword> var  res =  new  CRDGDMS.CRDProcedureInfoStruct();  //  本地服务 
var res1 = CRDProcedure.CRDProcedureInfoStruct(); // 客户服务
var response = MODE.Offline? res:res1;



但我收到错误无法确定条件表达式的类型,因为CRDProcedureInfoStruct和CRDProcedure.CRDProcedureInfoStruct之间没有隐式转换。



我怎样才能实现这一点。非常感谢。



提前感谢。

解决方案

基本上,你不能 - 除非两个类之间存在继承关系(即一个派生自另一个,或者它们都从同一个基类继承),或者你明确提供从一个到另一个的转换方法,系统无法做到。



这可能会有所帮助: https://msdn.microsoft.com/en-gb/library/aa288476(v = vs.71)的.aspx [ ^ ]

I am trying to use two services one i use when i use clients web service i.e in production mode and one local web service when my program runs in test mode, my problem is this that i want to use a single variable name for both the service type and want to decide in run time which service type to be used based on the mode i.e. production mode or test mode but i am getting following error

var res = new CRDGDMS.CRDProcedureInfoStruct();//local service
               var res1 = new CRDProcedure.CRDProcedureInfoStruct();//clients service
               var response = MODE.Offline ? res : res1;


but i get error "type of conditional expression cannot be determined because there is no implicit conversion between CRDProcedureInfoStruct and CRDProcedure.CRDProcedureInfoStruct.

how can i achieve this.any help will be appreciated.

thanks in advance.

解决方案

Basically, you can't - unless there is an inheritance relationship between the two classes, (i.e. one derives from the other, or they both inherit from the same base class), or you explicitly provide a cast method from one to the other, the system can't do it.

This may help: https://msdn.microsoft.com/en-gb/library/aa288476(v=vs.71).aspx[^]


这篇关于为两种服务类型使用相同的变量名称...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆