简体   繁体   中英

how to pass a struct into another struct

I want to pass a struct into another struct but the error i get is "name" doesn't exist in the current context , it's not included . How to make it known for the other struct

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 ;
    }

The name of the struct variable is asdu ;

Remove the struct keyword, use it like a normal variable like:

public struct iec_apdu
{
     iec_unit_id asdu;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM