On Tue, 11 Mar 2008 13:30:02 -0700, LPeter
<LP****@discussions.microsoft.comwrote:
I would copy the characters of a string variable to a fixed character
buffer
in a struct (and vice versa) in C#.
public struct S
{
...
public fixed char cBuff[16];
...
}
I tried to do this many way, but I often get the following compiler
error:
"error CS1666: You cannot use fixed size buffers contained in unfixed
expressions"
"Often"? In what context? Can you post an example of when you get that
error, and a clearer description of why you don't understand the error?
What is the simplest way to do this?
Well, the example you posted is fine, as far as it goes. So the real
question is, how are you trying to use a struct declared in that way, and
why isn't _that_ working?
My personal opinion is that you should think very carefully before using
"fixed". It's only needed in specialized situations, and like many
specialized expressions, is over-used. But if we take as granted that you
need to use a fixed char[] in a struct, there should be a way to explain
how to do that. But without more information about what you're trying to
do and why it's not working, it's not possible to reliably answer your
question.
Pete