Solved

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

Posted on 2013-12-17
6
370 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:DevoinIT
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39724589
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?
0
 

Author Comment

by:DevoinIT
ID: 39724653
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:
}
0
 

Author Comment

by:DevoinIT
ID: 39724661
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<>
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 11

Accepted Solution

by:
Angelp1ay earned 500 total points
ID: 39724703
You're treating QueryDto as if it is a single HumDto whereas in fact it has a member HumId which is itself many HumDtos.

I'm not sure what the aim is but if you wanted to get or set a HumId you need something like:
foreach(HumDto hd in QueryDto.HumId) {
hd.humid = "1234567W";
}

Open in new window

0
 

Author Comment

by:DevoinIT
ID: 39724830
I will try this and let you know.
0
 

Author Closing Comment

by:DevoinIT
ID: 39725019
This worked Excellent. I will post this out there for other.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question