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
Explain the security with aop?
Can a constructor be static in c#?
Explain about Oops concept
Which attribute adorn a test class to be picked up by the NUnit GUI in the NUnit test framework?
Can You Prevent Your Class From Being Inherited By Another Class?
What are c# i/o classes? What are the commonly used i/o classes?
What is the difference between array and list in c#?
How to update the gui from another thread in c#?
What is a generic class?
What is base class in c#?
How does array sort work?
Is null c# operator?
What Is An Interface Class?
What is console based application?
Can a constructor have a return type?