Link to home
Start Free TrialLog in
Avatar of DevoinIT
DevoinIT

asked on

Generic List Collection - IHow to add a string to the list

I have created a list collection and I am trying to pass a string back to it. It a data member in a WCF class.
Public List<HumDTO> HumID
{

    get;
    set;

}

when I get a instance of the class"

QueryDTO aDTO = new QueryDTO

Inside this instance is my list

I am trying to pass some value back into the list:

aDTO .HumID = "W352936514";

and I am getting a error
Cannot implicitly convert type string to System.Collection.Generic.List<>

Please let me know what I am doing wrong.
Avatar of Angelp1ay
Angelp1ay
Flag of United Kingdom of Great Britain and Northern Ireland image

Your field is of type List<HumDTO>
Your value is of type string

It's a little difficult to understand what you're trying to achieve. Could you tell us a little more about the HumDTO type?
Avatar of DevoinIT
DevoinIT

ASKER

Basically I have a ID number which was originally set-up as a string, But now we need the HumDTO to accept a list of IDs.

I created a class HumDTO :

[DataContract]
Public class HumDTO

{

[DataMember(IsRequired = true)]
public string HumID
{

    get;
    set;
}
}

Next I call the class above from another class which is called QueryDTO
[DataMember]
public List<HumDTO> HumaID
{

      get;
      set:
}
I created a test Case and her it is

QueryDTO qDTO = new QueryDTO();
qDTO.Accountnumber = "111111111";
qDTO .HumId = "1253647W";

Cannot implicitly convert type string to System.collection.Generic.List<>
ASKER CERTIFIED SOLUTION
Avatar of Angelp1ay
Angelp1ay
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will try this and let you know.
This worked Excellent. I will post this out there for other.