Solved

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

Posted on 2013-12-17
6
364 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now