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
What happens if a static constructor throws an exception?
What is a c# delegate?
What are bitwise logical operators?
In .Net, what is an assembly? Also explain the type of assembly.
Is it possible to inherit multiple interfaces?
What does void mean unity?
What is the difference between new and override in c#?
Are objects passed by reference in c#?
What is the difference between ref and out in c#?
What is a data set in c#?
What is _layout cshtml?
What is Dependency of Injection?
What is private static in c#?
Define assert() method? How does it work?
Can hashset contain duplicates c#?