Wpf Cast SelectedItemCollection Error CS0122 'SelectedItemCollection' is inaccessible due to its protection level,Convert System.Collections.IList to List

//the wrong demo
var temp = objs as SelectedItemCollection;

which will reported error, Error CS0122 'SelectedItemCollection' is inaccessible due to its protection level

 

The remedy should casted via System.Collections.IList as below

 System.Collections.IList items=objs as System.Collections.IList;
 if(items!=null && items.Count>0)
 {
     //To do
 }

 

System.Collections.IList iList=outerValue;
List<T> list=iList.Cast<T>().ToList();

 

posted @ 2024-04-07 14:06  FredGrit  阅读(14)  评论(0编辑  收藏  举报