How to get T from Type

BitSmithy 1,751 Reputation points
2021-10-02T20:04:00.337+00:00

Hello;

I know type, and I want to create Observable Collection of this type

public void MyMethod(Type T)
{

ObservableCollection<T> oc = new ObservableCollection<T>();
}
or

Type T;
T = MyClass

ObservableCollection<T> oc = new ObservableCollection<T>();

But this code doesnt work, how to do such think?

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daniele 1,996 Reputation points
    2021-10-03T09:05:29.32+00:00

    Should be like that

    public void MyMethod<T>()
    {
        ObservableCollection<T> oc = new ObservableCollection<T>();
    }
    

  2. BitSmithy 1,751 Reputation points
    2021-12-21T15:40:03.137+00:00
    0 comments No comments