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 difference between access specifier and access modifier in c#?
Can you access a hidden base class method in the derived class?
Difference between value and reference type.
What is the difference between early binding and late binding in c#?
What are functions in c#?
Is null c# operator?
What does console readline do in c#?
What is a Managed Code??
What is dll file in c#?
How many types of constructors are there in c#?
What is a shared assembly?
List down the fundamental oop concepts?
Explain what is the smallest unit of execution in .net?
How does dll hell solve in .net?
Are c# destructors the same as c++ destructors?