Why does C# not allow generic properties?

后端 未结 5 1624
野性不改
野性不改 2020-12-03 07:03

I was wondering why I can not have generic property in non-generic class the way I can have generic methods. I.e.:

public interface TestClass
{
   IEnumerabl         


        
5条回答
  •  情深已故
    2020-12-03 07:18

    I made somthing like that. It type checks at run time.

    public class DataPackage
    {
        private dynamic _list;
    
        public List GetList()
        {
            return (List)_list;
        }
    
        public void SetList(List list)
        {
            _list = list;
        }
    
        public string Name { get; set; }
    }
    

提交回复
热议问题