Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
swdev:dotnet:lists_and_observablecollections [2013/03/14 15:24]
smayr created
swdev:dotnet:lists_and_observablecollections [2013/03/14 15:35] (current)
smayr
Line 19: Line 19:
 Create a color list: Create a color list:
 <code csharp> <code csharp>
 +using System.Linq;  // Required for 'Where' lambda/linq statements
 +using System.Collections.ObjectModel; // Required for ObservableCollection
 +
 public class TColorList: List<TColor> public class TColorList: List<TColor>
 { {
 +    ///----------------------------------------------------------------------------------------
 +    /// Constructor
 +    ///----------------------------------------------------------------------------------------
 +    public TColorList()
 +    {
 +       PopulateList();
 +    }
 +    
 +    ///----------------------------------------------------------------------------------------
 +    /// Populate list
 +    ///----------------------------------------------------------------------------------------
 +    private void PopulateList()
 +    {
 +       Add(new TColor() { Name = "Red",   Type = TColorType.Red   });
 +       Add(new TColor() { Name = "Green", Type = TColorType.Green });
 +       Add(new TColor() { Name = "Blue",  Type = TColorType.Blue  });              
 +    }
  
 } }
Line 51: Line 71:
     {     {
         get { return this.Where(n => n.Type == aColorType).SingleOrDefault(); }         get { return this.Where(n => n.Type == aColorType).SingleOrDefault(); }
 +    }
 +    
 +    ///----------------------------------------------------------------------------------------
 +    /// Constructor
 +    ///----------------------------------------------------------------------------------------
 +    public TColorCollection()
 +    {
 +       PopulateCollection();
 +    }
 +    
 +    ///----------------------------------------------------------------------------------------
 +    /// Populate collection
 +    ///----------------------------------------------------------------------------------------
 +    private void PopulateCollection()
 +    {
 +       Add(new TColor() { Name = "Red",   Type = TColorType.Red   });
 +       Add(new TColor() { Name = "Green", Type = TColorType.Green });
 +       Add(new TColor() { Name = "Blue",  Type = TColorType.Blue  });              
     }     }
 } }
 </code> </code>