The use of custom class arrays and arrays of structures in C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.