I have a list of structs and I want to change one element. For example :
MyList.Add(new MyStruct("john");
MyList.Add(new MyStruct("peter");
Now I want to change one element:
MyList[1].Name = "bob"
However, whenever I try and do this I get the following error:
Cannot modify the return value of System.Collections.Generic.List.this[i...

I seem to remember reading something about how it is bad for structs to implement interfaces in CLR via C#, but I can't seem to find anything about it. Is it bad? Are there unintended consequences of doing so?
public interface Foo { Bar GetBar(); }
public struct Fubar : Foo { public Bar GetBar() { return new Bar(); } }
...

This question was already asked in the context of C#/.Net.
Now I'd like to learn the differences between a struct and a class in (unmanaged) C++. Please discuss the technical differences as well as reasons for choosing one or the other in OO design.
I'll start with an obvious difference:
If you don't specify public: or private:, memb...

Systems demand that certain primitives be aligned to certain points within the memory (ints to bits that are multiples of 4, shorts to bits that are multiples of 2, etc.). Of course, these can be optimized to waste the least space in padding.
my question is why doesn't GCC do this automatically? Is the more obvious heuristic (order va...

Being primarily a C++ developer the absence of RAII (Resource Acquisition Is Initialization) in Java and .NET has always bothered me. The fact that the onus of cleaning up is moved from the class writer to its consumer (by means of try finally or .NET's using construct) seems to be markedly inferior.
I see why in Java there is no suppor...

Structs seem like a useful way to parse a binary blob of data (ie a file or network packet). This is fine and dandy until you have variable size arrays in the blob. For instance:
struct nodeheader{
int flags;
int data_size;
char data[];
};
This allows me to find the last data character:
nodeheader b;
cout <<...

I have the following struct in C++:
#define MAXCHARS 15
typedef struct
{
char data[MAXCHARS];
int prob[MAXCHARS];
} LPRData;
And a function that I'm p/invoking into to get an array of 3 of these structures:
void GetData(LPRData *data);
In C++ I would just do something like this:
LPRData *Results;
Results = (LPRData *)mal...

Which would be a neat implemenation of a N-ary tree in C language?
Particulary, I want to implement an n-ary tree, not self-ballancing, with an unbound number of children in each node, in which each node holds an already defined struct, like this for example:
struct task {
char command[MAX_LENGTH];
int required_time;
};
...

Is it possible to initialize an array of pointers to structs?
Something like:
struct country_t *countries[] = {
{"United States of America", "America"},
{"England", "Europe"},
{"Ethiopia", "Africa"}
}
I want to do that in order to get the entities in not-contiguous memory, and the pointers to them in contiguous mem...

I just noticed that you can do this in C#:
Unit myUnit = 5;
instead of having to do this:
Unit myUnit = new Unit(5);
Does anyone know how I can achieve this with my own structs? I had a look at the Unit struct with reflector and noticed the TypeConverter attribute was being used, but after I created a custom TypeConverter for my st...