?
Solved

IList Question

Posted on 2007-07-31
8
Medium Priority
?
306 Views
Last Modified: 2010-04-15
I am getting a list of results from my database which is being returned in a constructor taking various parameters (ID, name, description etc).  This will be formed as an IList<MyConstruct>

From here I am appending additional data to this by doing a foreach:
foreach (MyConstruct in returnedList)
{
 // add data to constructor
}

My question is how can I then take the newly created ones in my foreach and make it an IList so that it fits in with my return type?
0
Comment
Question by:angus_young_acdc
  • 4
  • 4
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19598704
Why aren't you using the form List<MyConstruct>, and then you could just do something like this (if I understand what you are looking for):

List<MyConstruct> list = new List<MyConstruct>();
foreach (MyConstruct in returnedList)
{
  list.Add(MyConstruct);
}

return list;

Bob
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 19598734
Will give that a try Bob thanks.  Here is some more info on what I'm doing  just to see whilst I wait for my dlls to get ready:

IList<MyConstruct> returnedData = new List<MyConstruct>();
try
{
     returnedData = GetData();

    foreach(MyConstruct obj in returnedData)
    {
          // Have code here to get the new data to add
         MyConstruct updatedData = new MyConstruct(obj.ID, obj.Name, obj.Description, newData);
        returnedData.Add(updatedData);
    }
}
catch (Exception ex)
{
  throw ex;
}

return returnedData;

Would that be the right way to do it?  Or will that just add the new constructors along with the old ones meaning I get 2 sets of data?  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19598876
If GetData returns a list of MyConstruct objects, then it looks like you are going to get 2 sets of MyConstruct objects.

Bob
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Author Comment

by:angus_young_acdc
ID: 19599063
Yeah it returns a list of objects.  Is there anyway to not have the 2 different sets?  Only need the new one with the updated information to pass on.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 19600047
It looks like it returns a list of MyConstruct objects, so why would you need to turn around and add the MyConstruct object to the list that you already have built?  If you need to modify the properties of a MyConstruct instance, then you could do that without having to readd the object to the list.

Bob
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 19600088
How do you do that Bob?  What I want to do is get the data out that I need, append information to it, and then pass it onto another project.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19609396
>>append information to it
What do you mean by "append information"?

Bob
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 19617422
I meant adding more information to it.  Where a value was null originally I wanted to add something there.  Managed to get it sorted now thanks :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

850 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