locked
C++ to C# struct question RRS feed

  • Question

  • I'm new to C# and I'm attempting to migrate some of my C++ code into C#.  I've tried several different options and can't seem to solve this problem.

    I've got this struct...

    static struct
    {
        char *sType1;
        char *sType2;
        char *sType3;
        char *sType4;
    } KeyValues[] = {
        {_T("0"), _T("A"), _T("T"), _T("V")},
        {_T("1"), _T("U"), _T("X"), _T("X")},
        {_T("2"), _T("B"), _T("R"), _T("5")},
        {_T("3"), _T("V"), _T("V"), _T("J")},
        {_T("4"), _T("C"), _T("4"), _T("W")},
        {_T("5"), _T("W"), _T("H"), _T("D")},
        {_T("Z"), _T("T"), _T("5"), _T("N")}
        };

    What is the best way to do this same thing in C#?  It doesn't have to be a struct, that's just the way it was written in C++.

    Thank you!!!
    Tuesday, February 24, 2009 6:54 PM

Answers

  • Looks like you just need 4 strings. Perhaps something like this would do :

        struct KeyValues
        {
            public string sType1;
            public string sType2;
            public string sType3;
            public string sType4;
        }

    and you can declare the array as :

            KeyValues[] values = new KeyValues[]
            {
                new KeyValues(){ sType1 = "0", sType2 = "A", sType3 = "T", sType4 ="V" },
                new KeyValues(){ sType1 = "1", sType2 = "A", sType3 = "X", sType4 ="V" },
                new KeyValues(){ sType1 = "2", sType2 = "A", sType3 = "T", sType4 ="X" }
            };

    http://blog.voidnish.com
    • Proposed as answer by Sajan Emmanuel Wednesday, February 25, 2009 12:10 PM
    • Marked as answer by Rene Laviolette Wednesday, February 25, 2009 9:17 PM
    Tuesday, February 24, 2009 7:26 PM
    Moderator