none
C# Multidimensional arrays

    Question

  • Hello,

    I'm trying to put the following structure into an array so that I can input a string into my method, it will take the string and then decode it using the array. How this works is that the input string always has an even # of characters, each two characters in the input represents one character in the output, and also with each two characters the encryption differs based on the location within the string.

    For example an input string of "9244E2A05CE3" should return an output string of "abcdee" since the first two characters "92" are found to be "a" under the column 1 representing the location, in column 2 for the second output character we entered "44" so we output "b".

    We can note that as location along the input changes we need to use a different column array to find the output. However wouldn't it be easier to use a multidimensional array?

    l | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
    --------------------------------------------------- 
    a | 92 47 E0 A5 58 E7 BA F3 10 C2 D8 87 32 1B F4 1D 
    b | 91 44 E3 A6 5B E4 B9 F0 13 C1 DB 84 31 18 F7 1E 
    c | 90 45 E2 A7 5A E5 B8 F1 12 C0 DA 85 30 19 F6 1F 
    d | 97 42 E5 A0 5D E2 BF F6 15 C7 DD 82 37 1E F1 18 
    e | 96 43 E4 A1 5C E3 BE F7 14 C6 DC 83 36 1F F0 19 
    f | 95 40 E7 A2 5F E0 BD F4 17 C5 DF 80 35 1C F3 1A 
    g | 94 41 E6 A3 5E E1 BC F5 16 C4 DE 81 34 1D F2 1B 
    h | 9B 4E E9 AC 51 EE B3 FA 19 CB D1 8E 3B 12 FD 14 
    i | 9A 4F E8 AD 50 EF B2 FB 18 CA D0 8F 3A 13 FC 15 
    j | 99 4C EB AE 53 EC B1 F8 1B C9 D3 8C 39 10 FF 16 
    k | 98 4D EA AF 52 ED B0 F9 1A C8 D2 8D 38 11 FE 17 
    l | 9F 4A ED A8 55 EA B7 FE 1D CF D5 8A 3F 16 F9 10 
    m | 9E 4B EC A9 54 EB B6 FF 1C CE D4 8B 3E 17 F8 11 
    n | 9D 48 EF AA 57 E8 B5 FC 1F CD D7 88 3D 14 FB 12 
    o | 9C 49 EE AB 56 E9 B4 FD 1E CC D6 89 3C 15 FA 13 
    p | 83 56 F1 B4 49 F6 AB E2 01 D3 C9 96 23 0A E5 0C 
    q | 82 57 F0 B5 48 F7 AA E3 00 D2 C8 97 22 0B E4 0D 
    r | 81 54 F3 B6 4B F4 A9 E0 03 D1 CB 94 21 08 E7 0E 
    s | 80 55 F2 B7 4A F5 A8 E1 02 D0 CA 95 20 09 E6 0F 
    t | 87 52 F5 B0 4D F2 AF E6 05 D7 CD 92 27 0E E1 08 
    u | 86 53 F4 B1 4C F3 AE E7 04 D6 CC 93 26 0F E0 09 
    v | 85 50 F7 B2 4F F0 AD E4 07 D5 CF 90 25 0C E3 0A 
    w | 84 51 F6 B3 4E F1 AC E5 06 D4 CE 91 24 0D E2 0B 
    x | 8B 5E F9 BC 41 FE A3 EA 09 DB C1 9E 2B 02 ED 04 
    y | 8A 5F F8 BD 40 FF A2 EB 08 DA C0 9F 2A 03 EC 05 
    z | 89 5C FB BE 43 FC A1 E8 0B D9 C3 9C 29 00 EF 06 
    A | B2 67 C0 85 78 C7 9A D3 30 E2 F8 A7 12 3B D4 3D 
    B | B1 64 C3 86 7B C4 99 D0 33 E1 FB A4 11 38 D7 3E 
    C | B0 65 C2 87 7A C5 98 D1 32 E0 FA A5 10 39 D6 3F 
    D | B7 62 C5 80 7D C2 9F D6 35 E7 FD A2 17 3E D1 38 
    E | B6 63 C4 81 7C C3 9E D7 34 E6 FC A3 16 3F D0 39 
    F | B5 60 C7 82 7F C0 9D D4 37 E5 FF A0 15 3C D3 3A 
    G | B4 61 C6 83 7E C1 9C D5 36 E4 FE A1 14 3D D2 3B 
    H | BB 6E C9 8C 71 CE 93 DA 39 EB F1 AE 1B 32 DD 34 
    I | BA 6F C8 8D 70 CF 92 DB 38 EA F0 AF 1A 33 DC 35 
    J | B9 6C CB 8E 73 CC 91 D8 3B E9 F3 AC 19 30 DF 36 
    K | B8 6D CA 8F 72 CD 90 D9 3A E8 F2 AD 18 31 DE 37 
    L | BF 6A CD 88 75 CA 97 DE 3D EF F5 AA 1F 36 D9 30 
    M | BE 6B CC 89 74 CB 96 DF 3C EE F4 AB 1E 37 D8 31 
    N | BD 68 CF 8A 77 C8 95 DC 3F ED F7 A8 1D 34 DB 32 
    O | BC 69 CE 8B 76 C9 94 DD 3E EC F6 A9 1C 35 DA 33 
    P | A3 76 D1 94 69 D6 8B C2 21 F3 E9 B6 03 2A C5 2C 
    Q | A2 77 D0 95 68 D7 8A C3 20 F2 E8 B7 02 2B C4 2D 
    R | A1 74 D3 96 6B D4 89 C0 23 F1 EB B4 01 28 C7 2E 
    S | A0 75 D2 97 6A D5 88 C1 22 F0 EA B5 00 29 C6 2F 
    T | A7 72 D5 90 6D D2 8F C6 25 F7 ED B2 07 2E C1 28 
    U | A6 73 D4 91 6C D3 8E C7 24 F6 EC B3 06 2F C0 29 
    V | A5 70 D7 92 6F D0 8D C4 27 F5 EF B0 05 2C C3 2A 
    W | A4 71 D6 93 6E D1 8C C5 26 F4 EE B1 04 2D C2 2B 
    X | AB 7E D9 9C 61 DE 83 CA 29 FB E1 BE 0B 22 CD 24 
    Y | AA 7F D8 9D 60 DF 82 CB 28 FA E0 BF 0A 23 CC 25 
    Z | A9 7C DB 9E 63 DC 81 C8 2B F9 E3 BC 09 20 CF 26 
    0 | C3 16 B1 F4 09 B6 EB A2 41 93 89 D6 63 4A A5 4C 
    1 | C2 17 B0 F5 08 B7 EA A3 40 92 88 D7 62 4B A4 4D 
    2 | C1 14 B3 F6 0B B4 E9 A0 43 91 8B D4 61 48 A7 4E 
    3 | C0 15 B2 F7 0A B5 E8 A1 42 90 8A D5 60 49 A6 4F 
    4 | C7 12 B5 F0 0D B2 EF A6 45 97 8D D2 67 4E A1 48 
    5 | C6 13 B4 F1 0C B3 EE A7 44 96 8C D3 66 4F A0 49 
    6 | C5 10 B7 F2 0F B0 ED A4 47 95 8F D0 65 4C A3 4A 
    7 | C4 11 B6 F3 0E B1 EC A5 46 94 8E D1 64 4D A2 4B 
    8 | CB 1E B9 FC 01 BE E3 AA 49 9B 81 DE 6B 42 AD 44 
    9 | CA 1F B8 FD 00 BF E2 AB 48 9A 80 DF 6A 43 AC 45 
    | | D3 06 A1 E4 19 A6 FB B2 51 83 99 C6 73 5A B5 5C 
    ~ | 8D 58 FF BA 47 F8 A5 EC 0F DD C7 98 2D 04 EB 02 
    ` | 93 46 E1 A4 59 E6 BB F2 11 C3 D9 86 33 1A F5 1C 
    ! | D2 07 A0 E5 18 A7 FA B3 50 82 98 C7 72 5B B4 5D 
    @ | B3 66 C1 84 79 C6 9B D2 31 E3 F9 A6 13 3A D5 3C 
    # | D0 05 A2 E7 1A A5 F8 B1 52 80 9A C5 70 59 B6 5F 
    $ | D7 02 A5 E0 1D A2 FF B6 55 87 9D C2 77 5E B1 58 
    % | D6 03 A4 E1 1C A3 FE B7 54 86 9C C3 76 5F B0 59 
    ^ | AD 78 DF 9A 67 D8 85 CC 2F FD E7 B8 0D 24 CB 22 
    & | D5 00 A7 E2 1F A0 FD B4 57 85 9F C0 75 5C B3 5A 
    * | D9 0C AB EE 13 AC F1 B8 5B 89 93 CC 79 50 BF 56 
    ( | DB 0E A9 EC 11 AE F3 BA 59 8B 91 CE 7B 52 BD 54 
    ) | DA 0F A8 ED 10 AF F2 BB 58 8A 90 CF 7A 53 BC 55 
    _ | AC 79 DE 9B 66 D9 84 CD 2E FC E6 B9 0C 25 CA 23 
    - | DE 0B AC E9 14 AB F6 BF 5C 8E 94 CB 7E 57 B8 51 
    + | D8 0D AA EF 12 AD F0 B9 5A 88 92 CD 78 51 BE 57 
    = | CE 1B BC F9 04 BB E6 AF 4C 9E 84 DB 6E 47 A8 41 
    { | 88 5D FA BF 42 FD A0 E9 0A D8 C2 9D 28 01 EE 07 
    [ | A8 7D DA 9F 62 DD 80 C9 2A F8 E2 BD 08 21 CE 27 
    } | 8E 5B FC B9 44 FB A6 EF 0C DE C4 9B 2E 07 E8 01 
    ] | AE 7B DC 99 64 DB 86 CF 2C FE E4 BB 0E 27 C8 21 
    | | 8F 5A FD B8 45 FA A7 EE 0D DF C5 9A 2F 06 E9 00 
    \ | AF 7A DD 98 65 DA 87 CE 2D FF E5 BA 0F 26 C9 20 
    : | C9 1C BB FE 03 BC E1 A8 4B 99 83 DC 69 40 AF 46 
    ; | C8 1D BA FF 02 BD E0 A9 4A 98 82 DD 68 41 AE 47 
    " | D1 04 A3 E6 1B A4 F9 B0 53 81 9B C4 71 58 B7 5E 
    ' | D4 01 A6 E3 1E A1 FC B5 56 84 9E C1 74 5D B2 5B 
    < | CF 1A BD F8 05 BA E7 AE 4D 9F 85 DA 6F 46 A9 40 
    , | DF 0A AD E8 15 AA F7 BE 5D 8F 95 CA 7F 56 B9 50 
    > | CD 18 BF FA 07 B8 E5 AC 4F 9D 87 D8 6D 44 AB 42 
    . | DD 08 AF EA 17 A8 F5 BC 5F 8D 97 C8 7D 54 BB 52 
    ? | CC 19 BE FB 06 B9 E4 AD 4E 9C 86 D9 6C 45 AA 43 
    / | DC 09 AE EB 16 A9 F4 BD 5E 8C 96 C9 7C 55 BA 53 
    ¡ | 52 87 20 65 98 27 7A 33 D0 02 18 47 F2 DB 34 DD 
    ¢ | 51 84 23 66 9B 24 79 30 D3 01 1B 44 F1 D8 37 DE 
    £ | 50 85 22 67 9A 25 78 31 D2 00 1A 45 F0 D9 36 DF 
    ¤ | 57 82 25 60 9D 22 7F 36 D5 07 1D 42 F7 DE 31 D8 
    ¥ | 56 83 24 61 9C 23 7E 37 D4 06 1C 43 F6 DF 30 D9 
    ¦ | 55 80 27 62 9F 20 7D 34 D7 05 1F 40 F5 DC 33 DA 
    § | 54 81 26 63 9E 21 7C 35 D6 04 1E 41 F4 DD 32 DB 
    ¨ | 5B 8E 29 6C 91 2E 73 3A D9 0B 11 4E FB D2 3D D4 
    © | 5A 8F 28 6D 90 2F 72 3B D8 0A 10 4F FA D3 3C D5 
    ª | 59 8C 2B 6E 93 2C 71 38 DB 09 13 4C F9 D0 3F D6 
    « | 58 8D 2A 6F 92 2D 70 39 DA 08 12 4D F8 D1 3E D7 
    ¬ | 5F 8A 2D 68 95 2A 77 3E DD 0F 15 4A FF D6 39 D0 
    ® | 5D 88 2F 6A 97 28 75 3C DF 0D 17 48 FD D4 3B D2 
    ¯ | 5C 89 2E 6B 96 29 74 3D DE 0C 16 49 FC D5 3A D3 
    ° | 43 96 31 74 89 36 6B 22 C1 13 09 56 E3 CA 25 CC 
    ± | 42 97 30 75 88 37 6A 23 C0 12 08 57 E2 CB 24 CD 
    ² | 41 94 33 76 8B 34 69 20 C3 11 0B 54 E1 C8 27 CE 
    ³ | 40 95 32 77 8A 35 68 21 C2 10 0A 55 E0 C9 26 CF 
    ´ | 47 92 35 70 8D 32 6F 26 C5 17 0D 52 E7 CE 21 C8 
    µ | 46 93 34 71 8C 33 6E 27 C4 16 0C 53 E6 CF 20 C9 
    ¶ | 45 90 37 72 8F 30 6D 24 C7 15 0F 50 E5 CC 23 CA 
    · | 44 91 36 73 8E 31 6C 25 C6 14 0E 51 E4 CD 22 CB 
    ¸ | 4B 9E 39 7C 81 3E 63 2A C9 1B 01 5E EB C2 2D C4 
    ¹ | 4A 9F 38 7D 80 3F 62 2B C8 1A 00 5F EA C3 2C C5 
    º | 49 9C 3B 7E 83 3C 61 28 CB 19 03 5C E9 C0 2F C6 
    » | 48 9D 3A 7F 82 3D 60 29 CA 18 02 5D E8 C1 2E C7 
    ¼ | 4F 9A 3D 78 85 3A 67 2E CD 1F 05 5A EF C6 29 C0 
    ½ | 4E 9B 3C 79 84 3B 66 2F CC 1E 04 5B EE C7 28 C1 
    ¾ | 4D 98 3F 7A 87 38 65 2C CF 1D 07 58 ED C4 2B C2 
    ¿ | 4C 99 3E 7B 86 39 64 2D CE 1C 06 59 EC C5 2A C3 
    À | 33 E6 41 04 F9 46 1B 52 B1 63 79 26 93 BA 55 BC 
    Á | 32 E7 40 05 F8 47 1A 53 B0 62 78 27 92 BB 54 BD 
    Â | 31 E4 43 06 FB 44 19 50 B3 61 7B 24 91 B8 57 BE 
    Ã | 30 E5 42 07 FA 45 18 51 B2 60 7A 25 90 B9 56 BF 
    Ä | 37 E2 45 00 FD 42 1F 56 B5 67 7D 22 97 BE 51 B8 
    Å | 36 E3 44 01 FC 43 1E 57 B4 66 7C 23 96 BF 50 B9 
    Æ | 35 E0 47 02 FF 40 1D 54 B7 65 7F 20 95 BC 53 BA 
    Ç | 34 E1 46 03 FE 41 1C 55 B6 64 7E 21 94 BD 52 BB 
    È | 3B EE 49 0C F1 4E 13 5A B9 6B 71 2E 9B B2 5D B4 
    É | 3A EF 48 0D F0 4F 12 5B B8 6A 70 2F 9A B3 5C B5 
    Ê | 39 EC 4B 0E F3 4C 11 58 BB 69 73 2C 99 B0 5F B6 
    Ë | 38 ED 4A 0F F2 4D 10 59 BA 68 72 2D 98 B1 5E B7 
    Ì | 3F EA 4D 08 F5 4A 17 5E BD 6F 75 2A 9F B6 59 B0 
    Í | 3E EB 4C 09 F4 4B 16 5F BC 6E 74 2B 9E B7 58 B1 
    Î | 3D E8 4F 0A F7 48 15 5C BF 6D 77 28 9D B4 5B B2 
    Ï | 3C E9 4E 0B F6 49 14 5D BE 6C 76 29 9C B5 5A B3 
    Ð | 23 F6 51 14 E9 56 0B 42 A1 73 69 36 83 AA 45 AC 
    Ñ | 22 F7 50 15 E8 57 0A 43 A0 72 68 37 82 AB 44 AD 
    Ò | 21 F4 53 16 EB 54 09 40 A3 71 6B 34 81 A8 47 AE 
    Ó | 20 F5 52 17 EA 55 08 41 A2 70 6A 35 80 A9 46 AF 
    Ô | 27 F2 55 10 ED 52 0F 46 A5 77 6D 32 87 AE 41 A8 
    Õ | 26 F3 54 11 EC 53 0E 47 A4 76 6C 33 86 AF 40 A9 
    Ö | 25 F0 57 12 EF 50 0D 44 A7 75 6F 30 85 AC 43 AA 
    × | 24 F1 56 13 EE 51 0C 45 A6 74 6E 31 84 AD 42 AB 
    Ø | 2B FE 59 1C E1 5E 03 4A A9 7B 61 3E 8B A2 4D A4 
    Ù | 2A FF 58 1D E0 5F 02 4B A8 7A 60 3F 8A A3 4C A5 
    Ú | 29 FC 5B 1E E3 5C 01 48 AB 79 63 3C 89 A0 4F A6 
    Û | 28 FD 5A 1F E2 5D 00 49 AA 78 62 3D 88 A1 4E A7 
    Ü | 2F FA 5D 18 E5 5A 07 4E AD 7F 65 3A 8F A6 49 A0 
    Ý | 2E FB 5C 19 E4 5B 06 4F AC 7E 64 3B 8E A7 48 A1 
    Þ | 2D F8 5F 1A E7 58 05 4C AF 7D 67 38 8D A4 4B A2 
    ß | 2C F9 5E 1B E6 59 04 4D AE 7C 66 39 8C A5 4A A3 
    à | 13 C6 61 24 D9 66 3B 72 91 43 59 06 B3 9A 75 9C 
    á | 12 C7 60 25 D8 67 3A 73 90 42 58 07 B2 9B 74 9D 
    â | 11 C4 63 26 DB 64 39 70 93 41 5B 04 B1 98 77 9E 
    ã | 10 C5 62 27 DA 65 38 71 92 40 5A 05 B0 99 76 9F 
    ä | 17 C2 65 20 DD 62 3F 76 95 47 5D 02 B7 9E 71 98 
    å | 16 C3 64 21 DC 63 3E 77 94 46 5C 03 B6 9F 70 99 
    æ | 15 C0 67 22 DF 60 3D 74 97 45 5F 00 B5 9C 73 9A 
    ç | 14 C1 66 23 DE 61 3C 75 96 44 5E 01 B4 9D 72 9B 
    è | 1B CE 69 2C D1 6E 33 7A 99 4B 51 0E BB 92 7D 94 
    é | 1A CF 68 2D D0 6F 32 7B 98 4A 50 0F BA 93 7C 95 
    ê | 19 CC 6B 2E D3 6C 31 78 9B 49 53 0C B9 90 7F 96 
    ë | 18 CD 6A 2F D2 6D 30 79 9A 48 52 0D B8 91 7E 97 
    ì | 1F CA 6D 28 D5 6A 37 7E 9D 4F 55 0A BF 96 79 90 
    í | 1E CB 6C 29 D4 6B 36 7F 9C 4E 54 0B BE 97 78 91 
    î | 1D C8 6F 2A D7 68 35 7C 9F 4D 57 08 BD 94 7B 92 
    ï | 1C C9 6E 2B D6 69 34 7D 9E 4C 56 09 BC 95 7A 93 
    ð | 03 D6 71 34 C9 76 2B 62 81 53 49 16 A3 8A 65 8C 
    ñ | 02 D7 70 35 C8 77 2A 63 80 52 48 17 A2 8B 64 8D 
    ò | 01 D4 73 36 CB 74 29 60 83 51 4B 14 A1 88 67 8E 
    ó | 00 D5 72 37 CA 75 28 61 82 50 4A 15 A0 89 66 8F 
    ô | 07 D2 75 30 CD 72 2F 66 85 57 4D 12 A7 8E 61 88 
    õ | 06 D3 74 31 CC 73 2E 67 84 56 4C 13 A6 8F 60 89 
    ö | 05 D0 77 32 CF 70 2D 64 87 55 4F 10 A5 8C 63 8A 
    ÷ | 04 D1 76 33 CE 71 2C 65 86 54 4E 11 A4 8D 62 8B 
    ø | 0B DE 79 3C C1 7E 23 6A 89 5B 41 1E AB 82 6D 84 
    ù | 0A DF 78 3D C0 7F 22 6B 88 5A 40 1F AA 83 6C 85 
    ú | 09 DC 7B 3E C3 7C 21 68 8B 59 43 1C A9 80 6F 86 
    û | 08 DD 7A 3F C2 7D 20 69 8A 58 42 1D A8 81 6E 87 
    ü | 0F DA 7D 38 C5 7A 27 6E 8D 5F 45 1A AF 86 69 80 
    ý | 0E DB 7C 39 C4 7B 26 6F 8C 5E 44 1B AE 87 68 81 
    þ | 0D D8 7F 3A C7 78 25 6C 8F 5D 47 18 AD 84 6B 82 
    ÿ | 0C D9 7E 3B C6 79 24 6D 8E 5C 46 19 AC 85 6A 83 
    
    Above is the encryption/decryption chart used, the left most rows represent the output character, the top represents the location of the character along the output string, inside are the two character pair encryption codes for each character depending on where it is along the string. For example if the 'a' character were in the first location of the password being encrypted it would have an encoded value of "92XXXX" but if it was in the second "XX47XX", the decrypted passwords would look like so: "aXX", or "XaX" where the X's represent random characters.
    Sunday, June 14, 2009 3:34 AM

Answers

  • Hi,
      It seems you want to have a two dimentsional array. You can use the IList interface as Mr Cor Ligthert sayd. You can also use Jagged array for storing this
     kind of a structure.
      eg: 
        int[][] jaggedArray = new int[3][];

        jaggedArray[0] = new int[5];
        jaggedArray[1] = new int[4];
        jaggedArray[2] = new int[2];

     Instead of int you have to use any datatype to store your data.

    You can find the documentation of jagged arrays here.

    -- Thanks Ajith R
    • Marked as answer by Figo Fei Friday, June 19, 2009 3:30 AM
    Sunday, June 14, 2009 5:23 PM
  • See:

    Array Example
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by Figo Fei Friday, June 19, 2009 3:30 AM
    Sunday, June 14, 2009 7:34 PM
  • Hi,

    Arrays are (with the exception as it is completely unchangable like with an immage) not the way to go anymore.

    Have a look at all kind of lists where you have almost more types then there are problems.

    And then look at those who fullfil the IList contract (Interface)

    http://msdn.microsoft.com/en-us/library/5y536ey6.aspx
    Success
    Cor
    • Marked as answer by Figo Fei Friday, June 19, 2009 3:30 AM
    Sunday, June 14, 2009 5:58 AM

All replies

  • Hi,

    Arrays are (with the exception as it is completely unchangable like with an immage) not the way to go anymore.

    Have a look at all kind of lists where you have almost more types then there are problems.

    And then look at those who fullfil the IList contract (Interface)

    http://msdn.microsoft.com/en-us/library/5y536ey6.aspx
    Success
    Cor
    • Marked as answer by Figo Fei Friday, June 19, 2009 3:30 AM
    Sunday, June 14, 2009 5:58 AM
  • Hi,
      It seems you want to have a two dimentsional array. You can use the IList interface as Mr Cor Ligthert sayd. You can also use Jagged array for storing this
     kind of a structure.
      eg: 
        int[][] jaggedArray = new int[3][];

        jaggedArray[0] = new int[5];
        jaggedArray[1] = new int[4];
        jaggedArray[2] = new int[2];

     Instead of int you have to use any datatype to store your data.

    You can find the documentation of jagged arrays here.

    -- Thanks Ajith R
    • Marked as answer by Figo Fei Friday, June 19, 2009 3:30 AM
    Sunday, June 14, 2009 5:23 PM
  • See:

    Array Example
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by Figo Fei Friday, June 19, 2009 3:30 AM
    Sunday, June 14, 2009 7:34 PM