If there is similar, it is honored, if reproduced, please specify
The use of custom class arrays and arrays of structures in C #
Recently found many projects in a given array to implement a certain logic or processing is very troublesome, one-dimensional array, two-dimensional array,,, and so on need to go through n-multi-conversion, rather than write a custom array yourself, both convenient and save time, the following is an array of classes, in fact, the equivalent of defining an entity class, Just use it as an array in the form of
Class RGB
{
public byte red;
public byte Green;
public byte Blue;
Public RGB (byte r,byte g,byte b)
{
this.red = R;
This.green = g;
This.blue = b;
}
}
The above defines a class that is the same as the entity class
When using a class array, it is important to note that you must instantiate the
Class Test
{
Class Array
rgb[] RGB = newrgb[image.width*image.height];
BYTE Red,green,blue;
Rgb[0] = Newrgb (red,green,blue);
rgb[1].red = red;
Rgb[1].green = green;
Rgb[1].blue = blue;
rgb[2].red = red;
...
This makes it possible to use the
}
Here is the definition of a struct body
struct HSI
{
public int hue;
public int saturation;
public int intensity;
}
Class Test2
{
hsi[] HSI = new Hsi[image.width*image.height];
int hue;
int saturation;
int intensity;
Hsi[0].hue = hue;
Hsi[0].saturation = saturation;
Hsi[0].intensity = intensity;
Hsi[1].hue = hue;
...
This uses the structure array
}
In summary, a summary of the simple use of the custom class array and the custom structure array, in order to pay attention to later use, to avoid making me the same mistake, welcome everyone treatise
The use of custom class arrays and arrays of structures in C #