public string name;
public int rollNo;
public string this[int i]
{
get
{
switch(i)
{
case 0:
return name;
case 1:
return rollNo.ToString();
default:
return "";
}
}
set
{
switch (i)
{
case 0:
name = value;
break;
case 1:
rollNo = value;
break;
}
}
}
above is the code that I'm trying to execute but the problem is rollNo = value
shows this problem "Cannot convert from string to int". What I'd like to ask is, Does the value passed to the indexer need to be the same as the return type of indexer? If no please guide me what exactly I'm doing wrong.
-Thanks