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 is iqueryable and ienumerable in c#?
What is difference between encapsulation and abstraction in c#?
What do you mean by serialization in .NET?
What is the name of c# compiler?
What is the correct way of declaring an xml namespace?
How do I run managed code in a process?
How do I open the console?
What is type system in c#?
What is delegate in c#?
What is the main purpose of xml?
Explain how to add controls dynamically to the form using c#.net.
What is the difference between console application and windows application?
Explain clr in brief.
Expalin the way you implement inheritance by using VB.NET/C#?
What are the advantages of using partial classes?