Click here to Skip to main content
16,016,712 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,

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

C#
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 am trying to add list string and list double to the constructor like below


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



I am getting like below:
Input arguments are invalid
Posted

1 solution

try like this.

C#
for (int Index = 0; Index < cmnMsgIdsRYbuses.Count; Index++)
        {
           var item = cmnMsgIdsRYbuses[Index];
           GatewayTimeRYlist.Add(new MsgIdGatewayTimeMap(item.cmnMsgIdsRYbuses, item.GatewayTimeRYbuses));
        }
 
Share this answer
 
Comments
Member 10408451 9-Jan-14 5:25am    
Hi,

I have 5 classes which are using the same constructor

List<msgidgatewaytimemap> GatewayTimeRYlist = new List<msgidgatewaytimemap>();
List<msgidgatewaytimemap> GatewayTimeYGlist = new List<msgidgatewaytimemap>();
List<msgidgatewaytimemap> GatewayTimeGRlist = new List<msgidgatewaytimemap>();
List<msgidgatewaytimemap> GatewayTimeGOlist = new List<msgidgatewaytimemap>();
List<msgidgatewaytimemap> GatewayTimeORlist = new List<msgidgatewaytimemap>();

How can I add all of them to a single class
List<msgidgatewaytimemap> lsdfinal = new List<msgidgatewaytimemap>();

So, that I can return this lsdfinal list class instead of returning each class
Karthik_Mahalingam 9-Jan-14 5:29am    
chk my prv post.
http://www.codeproject.com/Answers/707897/How-to-add-list-strings-to-a-list#answer1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900