voglio fare questo: (EDIT: il codice di esempio male, ignorare e passare sotto)C# array all'interno di una struttura
struct RECORD {
char[] name = new char[16];
int dt1;
}
struct BLOCK {
char[] version = new char[4];
int field1;
int field2;
RECORD[] records = new RECORD[15];
char[] filler1 = new char[24];
}
Ma non essendo in grado di dichiarare la dimensione dell'array nella struct, come faccio a riconfigurare questo?
MODIFICA: Il motivo del layout è che sto utilizzando BinaryReader per leggere un file scritto con le strutture C. Usando BinaryReader e un C# struct union (FieldOffset (0)), voglio caricare l'intestazione come una matrice di byte, quindi leggerla come originariamente intesa.
[StructLayout(LayoutKind.Sequential)]
unsafe struct headerLayout
{
[FieldOffset(0)]
char[] version = new char[4];
int fileOsn;
int fileDsn;
// and other fields, some with arrays of simple types
}
[StructLayout(LayoutKind.Explicit)]
struct headerUnion // 2048 bytes in header
{
[FieldOffset(0)]
public byte[] headerBytes; // for BinaryReader
[FieldOffset(0)]
public headerLayout header; // for field recognition
}
fissi Buffer Dimensione - http://msdn.microsoft.it/it/us/library/zycewsya.aspx – Joren
@ Joren, perché non aggiungerlo come risposta? – atoMerz
Sapete che un C# 'char' è 2 byte mentre un C' char' di solito è 1 byte, giusto? – CodesInChaos