Solved

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

Posted on 2013-12-17
6
374 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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