structure element by index

  • Thread starter Thread starter Ahmet AKGUN
  • Start date Start date
A

Ahmet AKGUN

Hi;

I have a structure like

public struct MyStr
{
string elem1;
string elem2;
string elem3;
}

I want to have referance to this elements by index.
MStr.GetElem(2) must return a refarence to elem2.

is that possible ?
 
Ahmet AKGUN said:
I have a structure like

public struct MyStr
{
string elem1;
string elem2;
string elem3;
}

I want to have referance to this elements by index.
MStr.GetElem(2) must return a refarence to elem2.

is that possible ?

Not *very* easily - you'd need to use reflection, which is feasible but
doesn't perform well and isn't generally something to use without good
cause. Any reason you don't want to make it a string array internally?
 
Then I will lookup reflection api
thanks.


Jon Skeet said:
In that case I suggest you investigate reflection - but I don't know
whether reflection gives *any* guarantees about the order in which it
reports fields etc.
 
Back
Top