2
Answers

How to make List work?

van  tive

van tive

17y
2.2k
1

How to make generic List<T> for bool, Int16 , string  in the following code?

class myClass
{
string _dataType;
public List<Object> _list;
public myClass(string dataType)
 {
  _dataType=dataType;

 if (dataType=="bool")
    _list=new List<bool>();
 else if (dataType=="int16")
   _list=new List<Int16>();
 else if (dataType == "string")
   _list=new List<string>();
 else
   _list = new List<Object>();
 }
}

Error: Cannot implicitly convert type 'System.Collections.Generic.List<bool>' to 'System.Collections.Generic.List<object>'

Answers (2)