zoukankan      html  css  js  c++  java
  • C#中自定义类数组和结构数组的使用

    如有雷同,不胜荣幸,若转载,请注明

    C#中自定义类数组和结构数组的使用

    最近在很多项目中发现很多时候给定的数组要实现某个逻辑或处理很是麻烦,一维数组,二维数组,,,等等需要经过n多转换,还不如自己写一个自定义数组,既方便又节省时间,以下是类数组,其实相当于定义了一个实体类一样,只是使用的时候写成数组的形式在用

    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;

    }

    }

    以上定义了形如实体类一样的一个类

    类数组在使用的时候需要注意的是:必须要实例化

    Class Test

    {

    //类数组

    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;

    ...

    //这样就可以使用了

    }

    下面是定义一个结构体

    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;

    ...

    //这样使用结构数组

    }

    综上所述,就自定义类数组和自定义结构数组的简单使用做个总结,以便以后使用的时候注意,避免犯我同样的错误,欢迎大家斧正

  • 相关阅读:
    XML文件操作指南
    数字判断和文本框提交事件,WEB SERVICE等
    【转】JS回车提交
    nchar,char,varchar与nvarchar区别
    .NET对象的序列化
    这是发布的第一篇随笔
    Eclipse!!!!!!!!!!!!!!!!!!
    关于JLink驱动升级后不能使用的解决方法
    Python基本问题笔记
    用Python写的学校图书馆视频下载工具
  • 原文地址:https://www.cnblogs.com/ching2009/p/4293591.html
Copyright © 2011-2022 走看看