473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

structure element by index


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 ?

Nov 15 '05 #1
2 1772
Ahmet AKGUN <ak*********@hotmail.com> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

Then I will lookup reflection api
thanks.
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Ahmet AKGUN <ak*********@hotmail.com> wrote:
unfotunately I must get referances to structer elements and their types.
I have a common function that must do this for any structure given as
parameter
independent of structure elements.

So i need these for structure, element count, element referances and element data types.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
15
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
6
by: Laurent | last post by:
Hello, This is probably a dumb question, but I just would like to understand how the C# compiler computes the size of the managed structure or classes. I'm working on this class: public...
1
by: CptDondo | last post by:
I have a structure that looks like this: struct parameterSchedule_t { uint16_t waterFlow, uint16_t timerBase, uint16_t safetyDelay, uint16_t pressureRiseTimer, uint16_t stallTimer, uint8_t...
7
by: bahoo | last post by:
Hi, My data is organized like this, where A always goes from 1 to some number N: A 1 2 3 ... B 53,26 42,18 15,86 ... C 59 43 31 ......
7
by: tonyaim83 | last post by:
Hi... My input file is as follows :- A<-B<-C<-D A<-C<-E<-F<-P ....... ..... What i want is to first store the given input as follows :- {{{A,B},{B,C},{C,D}},{{A,C},{C,E},{E,F},{F,P}}} and...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.