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
Is namespace necessary in c#?
What is inner class in c#?
What is the difference between func and action delegate?
What is an object and a class?
What is difference between Trace and Debug
Is there throws keyword in c#?
Which is faster array or arraylist in c#?
What is nullable types in c#?
What is wpf c#?
Is namespace a class?
What is the difference between “dispose” and “finalize” variables in c#?
Define a jagged array in c#?
What’s a strong name?
What is the difference between a constant and a static readonly field?
i want the csharp questions&answeres