日期:2014-05-18  浏览次数:20826 次

请教一个类型转化的问题
基于OMRON Fins通信的实验,找了好几种方法,结果都遇到了vbstring在C#中类型不匹配的问题。
本人玩C#纯属业余爱好,想请大师们指点迷经。
C# code
//================================================================================================================
        //VB6.0事件处理 OnReceive()如下,收发数据正常。

        //Private Sub Command1_Click()
        //FinsMsg1.sendFinsCommand 0, 1, 0, "0101820064000002"
        //End Sub

        //Private Sub FinsMsg1_OnReceive()
        //Dim net As Integer, node As Integer, unit As Integer
        //Text1.Text = FinsMsg1.receiveMessage(net, node, unit, vbString)
        //End Sub
        //================================================================================================================

        private void button1_Click(object sender, EventArgs e)
        {
            axFinsMsg1.sendFinsCommand(0, 1, 0, "0101820064000002");
        }        
        private void axFinsMsg1_OnReceive(object sender, EventArgs e)
        {
            //public virtual object receiveMessage(ref short netID, ref short nodeID, ref short unitID, object messageType)
            //AxFINSMSGCTLLib.AxFinsMsg 的成员
            short a=0,b=0,c=0;
            object temp=new object();
            textBox1.Text = axFinsMsg1.receiveMessage(ref a,ref  b,ref c,temp);
            //错误    1    无法将类型“object”隐式转换为“string”。存在一个显式转换(是否缺少强制转换?)             
        }


------解决方案--------------------
C# code
textBox1.Text = axFinsMsg1.receiveMessage(ref a,ref  b,ref c,temp.toString());

------解决方案--------------------
receiveMessage是返回什么类型,如果是object,你需要 ToString(),才能赋值给Text