none
¿Error en los arreglos multidimencionales en visual C# 2010 express ? RRS feed

  • Pregunta

  • ¿Existe un error en el producto visual C# 2010 cuando se usan arreglos multidimencionales?

    Actualmente estoy traduciendo el código encontrado en la referencia: <!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>ES-MX</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:DontVertAlignCellWithSp/> <w:DontBreakConstrainedForcedTables/> <w:DontVertAlignInTxbx/> <w:Word11KerningPairs/> <w:CachedColBalance/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-520092929 1073786111 9 0 415 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin-top:0cm; margin-right:0cm; margin-bottom:10.0pt; margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; mso-themecolor:hyperlink; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:Calibri; mso-fareast-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} .MsoPapDefault {mso-style-type:export-only; margin-bottom:10.0pt; line-height:115%;} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 3.0cm 70.85pt 3.0cm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> http://www.ibm.com/developerworks/library/pa-bigiron5/

    a código C# pero al utilizar arreglos mutidimensionales parece que no considera el último elemento:

    Aquí va el código

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class CipherPair<T>{
        T Left;
        T Right;
        public CipherPair(T f, T s){
            Left=f;
            Right=s;
        }
        public T getLeft(){
            return Left;
        }
        public T getRight(){
            return Right;
        }
        public override String ToString()
        {
            return Left.ToString() + ", " + Right.ToString();
        }
    }

    // One single class for different Maps: Rotor, ReflectorMap
    public class Map<T>
    {
        private readonly int ALPHA_SIZE = 26;
        private readonly Char ALPHA_BASE = 'A';
        List<CipherPair<T>> contents = new List<CipherPair<T>>();
        public void SetContents(T[,] a)
        {
            for (int i = 0; i < a.GetUpperBound(0); ++i)
            {
                contents.Add(new CipherPair<T>(a[i,0], a[i,1]));
            }

        }

        public override String ToString()
        {
            String s="{";
            for (int i = 0; i<contents.Count;i++ )
            {
                s += "(" + contents[i].getLeft() + ", " + contents[i].getRight()+")";
            }
            s += "}";
             return s;
        }

        public int FindMatch(char inChar)
        {
            int idx=0;
            for (System.Collections.IEnumerator en = contents.GetEnumerator();
                en.MoveNext(); idx++)
            {
                System.Console.WriteLine(((CipherPair<T>)en.Current).ToString());
                if (((CipherPair<T>)en.Current).getRight().Equals(inChar))
                    break;
            }

            return idx;
        }

        public int FindDist(char pos1, char pos2)
        {
            if (pos2 > pos1)
                return (pos2 - pos1);
            else
                return ((ALPHA_SIZE - pos1) + pos2);
        }

        public List<CipherPair<T>> GetContents()
        {
            return contents;
        }


    }

    public class Enigma
    {
        private Map<char>  rotorOne;
        private Map<char>  rotorTwo;
        private Map<char> rotorThree;
        private Map<int> reflectorMap;
        private String inputFile = "Unspecified";
        private String outFile = "Unspecified";
        private String demoString;
        private String demoEnconde = "ENIGMA REVEALED";
        private String plainTextLine;
        private String cipherTextLine;
        private String refString = "ABCDEFGDIJKGMKMIEBFTCVVJAT";

        public Enigma()
        {
        }

        public void setRotorOne(char [,] r){
            rotorOne = RotoStart(r);
        }

        public void setRotorTwo(char[,] r)
        {
            rotorTwo = RotoStart(r);
        }

        public void setRotorThree(char[,] r)
        {
            rotorThree = RotoStart(r);
        }

        public void setReflectMap(Int32[,] c)
        {
            reflectorMap = ReflectorMapStart(c);
        }

        private Map<Int32> ReflectorMapStart(Int32[,] c)
        {
            Map<Int32> r = new Map<Int32>(); 
            r.SetContents(c);
            return r;
        }

        private Map<Char> RotoStart(Char[,] c )
        {
            Map<Char> r = new Map<Char>();
            r.SetContents(c);
            return r;
        }

        public Map<Char> GetRotorOne()
        {
            return rotorOne;
        }

        public Map<Char> GetRotorTwo()
        {
            return rotorTwo;
        }
        public Map<Char> GetRotorThree()
        {
            return rotorThree;
        }

    }

    public class Test
    {
        public static void Main(){
            Enigma e = new Enigma();
            char[,] cOne = new char[,]{
                {'A', 'E'}, {'B', 'K'}, {'C', 'M'}, {'D', 'F'},
                {'E', 'L'}, {'F', 'G'}, {'G', 'D'}, {'H', 'Q'},
                {'I', 'V'}, {'J', 'Z'}, {'K', 'N'}, {'L', 'T'},
                {'M', 'O'}, {'N', 'W'}, {'O', 'Y'}, {'P', 'H'},
                {'Q', 'X'}, {'R', 'U'}, {'S', 'S'}, {'T', 'P'},
                {'U', 'A'}, {'V', 'I'}, {'W', 'B'}, {'X', 'R'},
                {'Y', 'C'}, {'Z', 'J'}, {'#','#'}         
            };
            System.Console.WriteLine(cOne.GetUpperBound(0));
            e.setRotorOne(cOne);
            //  System.Console.WriteLine(e.GetRotorOne().GetContents()[26]); // <---Here Bug
            char[,] cTwo = new char[,]{
                {'A', 'A'}, {'B', 'J'}, {'C', 'D'}, {'D', 'K'},
                {'E', 'S'}, {'F', 'I'}, {'G', 'R'}, {'H', 'U'},
                {'I', 'X'}, {'J', 'B'}, {'K', 'L'}, {'L', 'H'},
                {'M', 'W'}, {'N', 'T'}, {'O', 'M'}, {'P', 'C'},
                {'Q', 'Q'}, {'R', 'G'}, {'S', 'Z'}, {'T', 'N'},
                {'U', 'P'}, {'V', 'Y'}, {'W', 'F'}, {'X', 'V'},
                {'Y', 'O'}, {'Z', 'E'}, {'#','#'}};
            e.setRotorTwo(cTwo);
            e.setRotorThree(new char[,]{
                {'A', 'B'}, {'B', 'D'}, {'C', 'F'}, {'D', 'H'},
                {'E', 'J'}, {'F', 'L'}, {'G', 'C'}, {'H', 'P'},
                {'I', 'R'}, {'J', 'T'}, {'K', 'X'}, {'L', 'V'},
                {'M', 'Z'}, {'N', 'N'}, {'O', 'Y'}, {'P', 'E'},
                {'Q', 'I'}, {'R', 'W'}, {'S', 'G'}, {'T', 'A'},
                {'U', 'K'}, {'V', 'M'}, {'W', 'U'}, {'X', 'S'},
                {'Y', 'Q'}, {'Z', 'O'}});
            e.setReflectMap(new int[,]{
                {0,  24}, {1,  17}, {2,  20}, {3,   7},
                {4,  16}, {5,  18}, {6,  11}, {7,   3},
                {8,  15}, {9,  23}, {10, 13}, {11,  6},
                {12, 14}, {13, 10}, {14, 12}, {15,  8},
                {16,  4}, {17,  1}, {18,  5}, {19, 25},
                {20,  2}, {21, 22}, {22, 21}, {23,  9},
                {24,  0}, {25, 19}});
            System.Console.WriteLine(e.GetRotorOne());
            System.Console.WriteLine(e.GetRotorTwo().FindMatch('E'));
        }
    }

     

    En "here bug" marcamos el error. ¿Es esto un error? si es así ¿en donde reportarlo?

    domingo, 6 de junio de 2010 3:08