Home > Net >  C # how to access to each member of the structure by the index number
C # how to access to each member of the structure by the index number

Time:12-22

Public struct dbConfig
{
Public int a;
Public int b;
Public float c;
};


For this structure, a, b, c of the index number of 0, 1, 2,

How to by 0, the index number to get a, b, c value?

CodePudding user response:

 
Public struct dbConfig
{
Public int a;
Public int b;
Public float c;

Public object this [int n]
{
The get
{
The switch (n)
{
Case 0: return a;
Case 1: return b;
Case 2: return c;
Default: throw new NotImplementedException ();
}
}
}
}

CodePudding user response:

The
refer to the original poster number007cool response:
public struct dbConfig
{
Public int a;
Public int b;
Public float c;
};


For this structure, a, b, c of the index number of 0, 1, 2,

How to by 0, the index number to get a, b, c value?

This it is ok to use a dictionary, first serialized as a dictionary, and then direct access to the serial number,
I often use, so don't know what is right for you,



CodePudding user response:

Next, and timber to stick a few lines of code you bai

CodePudding user response:

refer to the second floor??????????? Response:
Quote: refer to the original poster number007cool response:
public struct dbConfig
{
Public int a;
Public int b;
Public float c;
};


For this structure, a, b, c of the index number of 0, 1, 2,

How to by 0, the index number to get a, b, c value?

This it is ok to use a dictionary, first serialized as a dictionary, and then direct access to the serial number,
I often use, so don't know what is right for you,





Next, and timber to stick a few lines of code you bai
  •  Tags:  
  • C#
  • Related