Question about filling array's

For my IR project i want to setup a array with IR protocol defines; for the structure i created a class like below.

  public class IRType {
    string Name ;     // protocol name
    byte   Type;        // Bit 0 .. 1 is Carrier frequency  00 = 36
                        //                                  01 = 38
                        //                                  10 = 40
                        //                                  11 = 56
                        // Bit 3      code type
                        //            0 = Space
                        //            1 = shift
                        // Bit 4      Check Headerspace len 1 = yes
    byte   Bitsize      ;
    ushort HeaderPulse ;
    ushort HeaderSpace ;
    ushort OnePulse    ;
    ushort OneSpace    ;
    ushort NullPulse   ;
    ushort NullSpace   ;
    ushort StopPulse   ;
    ushort stopSpace   ;
    ushort StopEnd     ;
    ulong  AddressMask ;
    ulong  CommandMask ;
    byte   TroggleBit  ;

    public IRType(string aName, byte aType, byte aBitsize, 
                  ushort aHeaderPulse, ushort aHeaderSpace, ushort aOnePulse,    ushort aOneSpace, 
                  ushort aNullPulse,   ushort aNullSpace,   ushort aStopPulse,   ushort astopSpace,
                  ushort aStopEnd,     ulong  aAddressMask, ulong  aCommandMask, byte   aTroggleBit) {
        Name           = aName ;
        Type           = aType ;     
        Bitsize        = aBitsize;    
        HeaderPulse    = aHeaderPulse;
        HeaderSpace    = aHeaderSpace;
        OnePulse       = aOnePulse   ;
        OneSpace       = aOnePulse   ;
        NullPulse      = aNullPulse  ;
        NullSpace      = aNullSpace  ;
        StopPulse      = aStopPulse  ;
        stopSpace      = astopSpace  ;
        StopEnd        = aStopEnd    ;
        AddressMask    = aAddressMask;
        CommandMask    = aCommandMask;
        TroggleBit     = aTroggleBit ;
     }
  }

now i want to create a array like this

        const IRType[] defIRProtocols = new IRType[2]; 

But now i need to fill the above array with the real defines like i did in a PIC project.


//  DefCount = 2;
//  IRdefType: array[0..1] of array [0..10] of dword = (
//    ('A', $0001080E,  974,  786,  950,  788,  950,  788,   0,   0,   0), // RC5
//    ('B', $0002080F, 1788,  878,  875,  875,  875,  875, 980,   0,   0));

is there a way to to setup this. I have seen some examples some where about adding classes to the array but now i need it i cant find where i did find it before.

thanks

Niels

You mean something like:

 const IRType[] defIRProtocols = new IRType[2] {
new IRType("A", 1.....),
new ...
}; 

yes that is wat i mend

On last question on this matter i was trying to have some default parameters at the constructor method but C# give an error that it was not allowed. I have search the both e-book’s (“The beginers quide” and “Programmers Heaven’s C# School”) but i cant find the reason.

Default parameters is a c#4 feature?

I’m not sure about that. i found the option on the Internet but i closed the page already :slight_smile:

Are we talking about C# 4.0 optional parameters ? This will allow you to do something like


public void SendMail(string toAddress, string bodyText, bool ccAdministrator = true, bool isBodyHtml = false)
{
      // Full method here
}

You can work around this using method overloading, create overloading parameters. Here is an example that I found:


class MyClass
{
    static string myMethod(string precip, string country, string location)
    {
        return string.Format("The {0} in {1} stays mainly in the {2}.",
            precip, country, location );
    }

    static string myMethod(string precip, string country )
    {
        return myMethod(precip, country, "plain");
    }

    static string myMethod()
    {
        return myMethod("rain", "Spain", "plain");
    }
 
    static void Main(string[] args)
    {
        Console.WriteLine(myMethod());
        Console.WriteLine(myMethod("snow", "Walla Walla"));
    }
}