Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have one collection object which allready having 3 items .i want to add one extra field in each 3 item.How to do it ?

Thanks
Posted
Comments
thams 4-May-12 2:43am    
Can u explain a bit more?
In the collection you are adding an object of type say cls1, which has say n properties. you are trying to set value for the nth property?
Is it correct?

You can't add a field to items in a collection - you need to add the field to the definition of the item, then it will automatically be in each item you add. Normally, you do this at design time, not run time.

What are you trying to achieve here?
 
Share this answer
 
hi
refer this link

Add items to collection[^]
 
Share this answer
 
Hi there,

try this:

C#
IEnumerable<string> ReadLines()
{
     string s;
     do
     {
          s = Console.ReadLine();
          yield return s;
     } while (s != "");
}

IEnumerable<string> lines = ReadLines();
lines.Add("foo") // so what would this supposed to do??

What you can do, however, is creating a new IEnumerable object (of unspecified type), which, when enumerated, will provide all items of the old one, plus some of your own. You use Enumerable.Concat for that:
C#
items = items.Concat(new[] { "foo" });

All the best..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900