如何将参数传递给构造函数 [英] How can I pass arguments to the constructor

查看:111
本文介绍了如何将参数传递给构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个构造函数,它具有字符串和双值的输入参数



Hi,

I have a constructor which is having input arguments of string and double values

public class MsgIdGatewayTimeMap
        {
            string msgId;
            double gatewayTime;
           
            public string MsgId
            {
                get
                {
                    if (!String.IsNullOrEmpty(msgId))
                        return msgId.ToUpper();
                    else
                        return string.Empty;
                }

                set { msgId = value; }
            }

            public double GatewayTime
            {
                get
                {
                    //Double.IsNullOrEmpty(timeStamp)
                    return gatewayTime;
                    //else
                    //    return string.Empty;
                }

                set { gatewayTime = value; }
            }

            public MsgIdGatewayTimeMap(string msgId, double gatewayTime)
            {
                
                this.msgId = msgId;
                this.gatewayTime = gatewayTime;

            }

        }







I我正在尝试将列表字符串和列表double添加到构造函数中,如下所示








I am trying to add list string and list double to the constructor like below


for (int Index = 0; Index < cmnMsgIdsRYbuses.Count; Index++)
                {
                    GatewayTimeRYlist.Add(new MsgIdGatewayTimeMap(cmnMsgIdsRYbuses, GatewayTimeRYbuses));
                }







我的情况如下:

输入参数无效




I am getting like below:
Input arguments are invalid

推荐答案

尝试这样。



try like this.

for (int Index = 0; Index < cmnMsgIdsRYbuses.Count; Index++)
        {
           var item = cmnMsgIdsRYbuses[Index];
           GatewayTimeRYlist.Add(new MsgIdGatewayTimeMap(item.cmnMsgIdsRYbuses, item.GatewayTimeRYbuses));
        }


这篇关于如何将参数传递给构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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