c# - Add elements from IList to ObservableCollection -
I have an observation resolution, and I want to set an ILI content on it. Now I can just create a new instance of the collection ..:
Public Supervision column & lt; Bars & gt; Obs = new inspectory collection & lt; Bars & gt; (); Public Zero Fu (IELIT & Lt; Bar & gt; List) {obs = New Observational Collection & lt; Bars & gt; (List); }
But how can I actually take the contents of the IList and add it to my existing Observe Collection? Should I have a loop on all the elements, or is there any better way?
public void Foo (IList & lt; times> list) {foreach (var alm in the list) obs.Add (elm); }
you can
public void Foo (IList & lt; Bar & gt; List) {List. ToList (). ForEach (obs.Add); }
Or as an extension method,
public static Zero AddRange & lt; T & gt; (This observation: collections & lt; T & gt; collections, IEnumerable & lt; T & gt; items) items.ToList () foreach (collection.Add). }
Comments
Post a Comment