ExtensionMethod.NET Home of 820 C#, Visual Basic, F# and Javascript extension methods

ToObservableCollection

Return observable collection for IList object.

Source

/// <summary>
/// To the observable collection.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <returns>ObservableCollection&lt;T&gt;.</returns>
public static ObservableCollection<T> ToObservableCollection<T>(this IList<T> value) where T : class
{
    if (value == null)
    {
        return null;
    }

    var observableCollection = new ObservableCollection<T>(value);
    return observableCollection;
}

Example

var cityList = new List<string> { "NewYork", "London" };
var cityListObsCollection = cityList.ToObservableCollection();

Author: Muhammad Shoaib Ijaz

Submitted on: 16 sep 2016

Language: C#

Type: IList

Views: 1720