I have made a function today. I need to use multiple arrays in a class,
An array must be indexed to call an array.
I checked one msdn class and only one this indexer exists.
So how to construct indexes for so many arrays?
I found a way to know the decision in the jar
View plaincopy to clipboardprint?
Using System;
Namespace TestUse
{
/// <Summary>
/// Summary description for Muliti.
/// </Summary>
Public class Muliti
{
Public Muliti ()
{
//
// TODO: Add constructor logic here
//
}
Private string [] test1;
Private object [] test2;
Private int [] test3;
Public object this [string arrname, int index] {
Get {
Switch (arrname ){
Case "test1": return test1 [index];
Case "test2": return test2 [index];
Case "test3": return test3 [index];
Default: return null;
}
}
Set {
Switch (arrname)
{
Case "test1": test1 [index] = value. ToString (); break;
Case "test2": test2 [index] = value; break;
Case "test3": test3 [index] = (int) value; break;
Default: break;
}
}
}
Public void setUpArray (){
Test1 = new string [3];
Test2 = new object [2];
Test3 = new int [4];
}
}
}
Using System;
Namespace TestUse
{
/// <Summary>
/// Summary description for Muliti.
/// </Summary>
Public class Muliti
{
Public Muliti ()
{
//
// TODO: Add constructor logic here
//
}
Private string [] test1;
Private object [] test2;
Private int [] test3;
Public object this [string arrname, int index] {
Get {
Switch (arrname ){
Case "test1": return test1 [index];
Case "test2": return test2 [index];
Case "test3": return test3 [index];
Default: return null;
}
}
Set {
Switch (arrname)
{
Case "test1": test1 [index] = value. ToString (); break;
Case "test2": test2 [index] = value; break;
Case "test3": test3 [index] = (int) value; break;
Default: break;
}
}
}
Public void setUpArray (){
Test1 = new str