?
Solved

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

Posted on 2013-12-17
6
Medium Priority
?
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
LVL 11

Accepted Solution

by:
Angelp1ay earned 2000 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

764 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