Click here to Skip to main content
12,240,822 members (48,168 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# WPF
How can I loop through an observablecollection using a foreach loop???
Posted 28-Dec-12 1:33am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

for xample you can leverage this snippet:
ObservableCollection<string> obsColl=new ObservableCollection<string>(){"1","2","3"};
foreach(var data in obsColl)
{
Console.WriteLine(data);
}
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You could convert the items to a List and then try obcolls.ToList().ForEach(i => i.DoStuff());.
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

private ObservableCollection calculate = new ObservableCollection();

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

public class Calculations
{
    private string _results;
 
    public string Result
    {
        get { return this._results; }
        set { this._results = value; }
    }
}
  Permalink  
v2
Comments
Richard Deeming 26-Jan-15 10:25am
   
This question is from December 2012 - over two years ago!
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 26 Jan 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100