Creating an Array / List of Structures When a Structure Contains an Array / List

I'm new to C #, usually a C programmer, so it's hard for me to figure out which method is better to use. Hope I can get some advice to help me decide.
I have a structure that looks like this (I did it as I would in C):

struct structData
{
    long type;
    long myArray[50];
    string text;
}

I am creating an array of this structure that I can constantly read / write globally / publicly. (I will need to store the data there so that I can get it later)

structData arrayOfStructs[50];  

The goal would be to access the following data:

arrayOfStructs[0].type = 123;
arrayOfStructs[0].myArray[0] = 456;

#, :
"myArray" 50,
"... = new ...",

-, List < > ? ?
-, , , / ? ? , longs.

+3
3
public class StructData
{
    public long type;
    public long[] myArray = new long[50];
    public string text;
}

StructData[] datas = new StructData[100];

for (int i = 0; i < datas.Length; i++)
{
    datas[i] = new StructData();
}

, , , "" (, structs . , ) , , .NET, 4 int ( Guid). , .

, , , , , ( ). , - . , , ( , , . int , std ). "" , .

+4

, , C- #. , .

# . . , struct v, . , , :

-, , , . , . ( C) :

long[] myArray = new long[50];

, , fixed, , .

# , C. .

+2

, - , / , .

unsafe struct structData 
{     
    int type;
    fixed int myArray[50]; // long is 64-bit in C# was that intentional?
    string text; // string is a managed type
}

C, C #, . # , , , , .

A good place to start would be to study the C # memory model, as it explains the many subtle but important differences between value types and link types.

0
source

All Articles