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 (); } } } }