You have several options:
private void SetListData<T>(List<T> MyList) where T : class
or
ItemCollection = new ObservableCollection<object>(MyList.Cast<object>());
If you have a List<T> known reference type, it can work, although the type parameter is not an object :
var list = new List<string>(); var observable = new ObservableCollection<object>(list);
But in this case, you are using a generic parameter that is not a known reference type; it may be the type / structure of the value. They can be “boxed” as object , but are not essentially object s.
Thus, you must either restrict this parameter to always be a reference type, or allow any type T , and make an explicit cast to object inside the body of the method.
source share