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 manifest in c#.
What is a destructor in c#?
List down the commonly used types of exceptions in .net
Which function is the entry point for a DLL in MS Windows 3.1?
Can you mark static constructor with access modifiers?
What is namespace in oops?
Define an array?
What is the difference between “finalize” and “finally” methods in c#?
What is a static in c#?
What do multicast delegates mean?
What is the base class from which all value types are derived?
Can we write class inside a class in c#?
What is a sealed class?
How we convert private assembly into public assembly?
What will a loop recorder show?