Question: I'm converting some code from C++ to C# as a method to learn C#. In my C++ code I have

```
struct ChArray{
    char ch[8];
};

bool operator < (const ChArray& arrA, const ChArray& arrB);

```

In my C++, I can do things like:

```
map<ChArray, double>::iterator s;
for(s = settings.begin(); s != settings.end(); s++){
    out.write(reinterpret_cast<const char*>(&s->first), sizeof(ChArray));
}

```

The question is what is necessary to accomplish the same things in C#?

Not the map part (I know to use Dictionary), but rather, how do I create a set sized structure that can be easily written to and read from a file?

I've tried several combinations, all result in some error which seems like it would cause a problem later on when writing.

For instance, with a structure, I can't define the default size, which means I have to use new to dynamically allocate memory, which means (to me as a C++ programmer) that there would be no accurate way to guarantee the size of the structure when the file is being read, because the dynamic allocation could have been anything when the structure was initialized.

Maybe I'm just not aware of some c# power that would clear up this mess.

Answer: 
I recommend that you try to work at a higher level in C#. Especially if you want to get to know the language. C# trades of some low-level capabilities for vastly increased productivity. Embrace that.

What you want is directly translatable to C# using [Fixed Size Buffers](http://msdn.microsoft.com/en-us/library/zycewsya.aspx). Alternatively, you could use the `StructLayoutAttribute` to set a fixed size for a struct and control member layout. C# supports unsafe code quite well. This is often used for interop with native APIs.
I think you can use class ChArray instead of structure ChArray
And in your default contructor you can allocate a array of char with size = 8.