question

BitSmithy-4663 avatar image
0 Votes"
BitSmithy-4663 asked danielescipioni edited

How to get T from Type

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?

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

danielescipioni avatar image
0 Votes"
danielescipioni answered danielescipioni edited

Should be like that

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


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

II know that, but i found a scenario where this method doesnt work, so I must do a work around.

I must pass Type to class, and next use the Type as generic parameter, for other class

I dont know if such way is possible, so I am posting.

0 Votes 0 ·

Which is the scenario where this doesn't works?

0 Votes 0 ·