如何将结构传递给另一个结构

时间:2016-05-02 12:19:40

标签: c#

我想将结构传递给另一个结构但是我得到的错误是“name”在当前上下文中不存在,它不包括在内。如何让它知道其他结构

public struct iec_unit_id
    {
        internal byte iec_unit_id_data1;
        internal byte iec_unit_id_data2;

        public byte type_id;         //Type_identification

        public byte num
        {
            get            { return (byte)(iec_unit_id_data1 & 0x7f); }
            set            { iec_unit_id_data1 = (byte)((iec_unit_id_data1 & ~0x7f) | (value & 0x7f)); }
        }                                 //Number of Objects:7;
        public byte sq
        {
            get
            { return (byte)((iec_unit_id_data1 >> 7) & 0x01); }
            set
            { iec_unit_id_data1 = (byte)((iec_unit_id_data1 & ~(0x01 << 7)) | (value & 0x01) << 7); }
        }                                 // sequenced/not sequenced address:1;

        public byte cause
        {
            get            { return (byte)(iec_unit_id_data2 & 0x3f); }
            set            { iec_unit_id_data2 = (byte)((iec_unit_id_data2 & ~0x3f) | (value & 0x3f)); }
        }                             //cause of transmission:6;
        public byte pn
        {
            get            { return (byte)((iec_unit_id_data2 >> 6) & 0x01); }
            set            { iec_unit_id_data2 = (byte)((iec_unit_id_data2 & ~(0x01 << 6)) | (value & 0x01) << 6); }
        }                               // pn:1; positive=1 negative=0
        public byte t
        {
            get            { return (byte)((iec_unit_id_data2 >> 7) & 0x01); }
            set            { iec_unit_id_data2 = (byte)((iec_unit_id_data2 & ~(0x01 << 7)) | (value & 0x01) << 7); }
        }                               // test : 1;


        public byte oa;             //Originator Adress
        public ushort ca;           // ASDU Common Adress
    }

    public struct iec_apdu
    {
        byte start;
        byte length;
        byte NS;
        byte NR;
        struct iec_unit_id asdu ;
    }

struct变量的名称是asdu;

1 个答案:

答案 0 :(得分:4)

删除struct关键字,像普通变量一样使用它:

public struct iec_apdu
{
     iec_unit_id asdu;
}