Re: syntax for fixed array in C#?
From: Austin Ehlers (liberal*number_eight*_at_ku.edu)
Date: 08/03/04
- Next message: Job Lot: "Re: Joining DataTables"
- Previous message: Donald Adams: "Directory.Copy"
- In reply to: PHil Coveney: "syntax for fixed array in C#?"
- Next in thread: PHil Coveney: "syntax for fixed array in C#?"
- Reply: PHil Coveney: "syntax for fixed array in C#?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 02 Aug 2004 22:02:19 -0500
>
> [StructLayout(LayoutKind.Explicit, Size=120, CharSet=CharSet.Auto)]
> public class Foo
> {
> [FieldOffset(0)] public byte A;
> [FieldOffset(40)] public byte B;
> [FieldOffset(80)] public byte C;
> }
>
<snip>
Assuming the above Foo, this code will work
Foo foo=new Foo();
//call Legacy
string str=null;
fixed(byte* bP=&foo.A)
{
byte[] A=new byte[40];
for(int x=0;x<A.Length;x++)
A[x]=bP[x];
str=Encoding.ASCII.GetString(A); //if the bytes use
all 8 bits, you'll get bad values. Look at other Encoding.* classes
}
You can also declare the byte fields as byte* to save a step.
Austin
- Next message: Job Lot: "Re: Joining DataTables"
- Previous message: Donald Adams: "Directory.Copy"
- In reply to: PHil Coveney: "syntax for fixed array in C#?"
- Next in thread: PHil Coveney: "syntax for fixed array in C#?"
- Reply: PHil Coveney: "syntax for fixed array in C#?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|