Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I loop through an observablecollection using a foreach loop???
Posted

You could convert the items to a List and then try obcolls.ToList().ForEach(i => i.DoStuff());.
 
Share this answer
 
Comments
Richard Deeming 26-Jan-15 10:25am    
This question is from December 2012 - over two years ago!
Abhinav S 26-Jan-15 10:36am    
It appeared suddenly and and answered it.
Richard Deeming 26-Jan-15 10:38am    
Solution #2 pushed it up the list.
private ObservableCollection<calculations> calculate = new ObservableCollection<calculations>();

foreach (Calculations calc in calculate)
{
//access the property
mailing.Body += calc.Result + "\n";
}

C#
public class Calculations
{
    private string _results;

    public string Result
    {
        get { return this._results; }
        set { this._results = value; }
    }
}
 
Share this answer
 
v2
Comments
Richard Deeming 26-Jan-15 10:25am    
This question is from December 2012 - over two years ago!
Richard!i! 6-May-21 8:26am    
I'm reading this solution almost 10 years later. What's the issue with providing answers at a later date. It's still helpful.
Richard Deeming 18-May-21 8:49am    
Aside from the fact that there was no explanation, it doesn't demonstrate anything different to the original solution posted three years earlier. The original solution already demonstrates how to use foreach with an ObservableCollection; there was no need to resurrect the question to show exactly the same thing!
Member 10798081 26-Jan-15 13:10pm    
I landed to this answer at work today, so I thought I'd post my solution so that the next guy who has the same problem could see a variety of the same solution.
for xample you can leverage this snippet:
C#
ObservableCollection<string> obsColl=new ObservableCollection<string>(){"1","2","3"};
foreach(var data in obsColl)
{
Console.WriteLine(data);
}
 
Share this answer
 
v2

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