Indexers in c#?

Answer Posted / srinath thanuku

Sample code to use Indexers when there are more than one
variable in a Class.

class IndexerExample
{
private string[] SkillSet = new string[5];
private string userName;
private int salary;
public string this[int indexrange]
{
set
{
SkillSet[indexrange] = value;
}
get
{
return SkillSet[indexrange];
}
}
public int sal
{
get
{
return salary;
}
set
{
salary = value;
}
}
public string name
{
get
{
return userName;
}
set
{
userName = value;
}
}

}

Creating an Object of the Above Class:
IndexerExample obj = new IndexerExample();
obj[0] = "C#";
obj[1] = "VB.Net";
obj[2] = "ASP.Net";
obj[3] = "SQL Server 2005";
obj[4] = "JScript.Net";
obj.sal = 1000;
obj.name ="Madhavi K.";

Is This Answer Correct ?    14 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is namespace necessary in c#?

491


What is inner class in c#?

522


What is the difference between func and action delegate?

491


What is an object and a class?

557


What is difference between Trace and Debug

552






Is there throws keyword in c#?

491


Which is faster array or arraylist in c#?

483


What is nullable types in c#?

502


What is wpf c#?

495


Is namespace a class?

496


What is the difference between “dispose” and “finalize” variables in c#?

487


Define a jagged array in c#?

486


What’s a strong name?

525


What is the difference between a constant and a static readonly field?

531


i want the csharp questions&answeres

1491