Nested Generics

I asked about this before, but I did not get the question correctly, so the answer was missed.

If I have a method that returns ObservableColletion<T>, how will I use it in another general method.

Will be

method2<ObservableCollection<T>>(){} 

- way.

I am trying to create a generic EventArgs result that will pass the results of an Ado.NET Dataservices request to all subscribers. Inside, I want to not be able to pass a strongly typed EntityCollection that is returned [Generated by Ado.NET 1.5]

So yes, my question is formulated ObservableCollectionbecause I did not want the entire ada.net dataservices error to be confused.

Greetings Dave

+3
source share
1 answer

; item ? , T :

public ObservableCollection<T> SomeMethod<T>()
{
    var data = new ObservableCollection<T>();
    data.Add(default(T)); // or whatever
    return data;
}

ObservableCollection<Order> orders = SomeMethod<Order>() .. , ...

public TList SomeMethod<TList, T>()
    where TList : class, IList<T>, new()
{
    var data = new TList();
    data.Add(default(T)); // or whatever
    return data;
}

. , , TList, T ... .

+4

Source: https://habr.com/ru/post/1710947/


All Articles