Exit beyond C#



  • There's a code:

    public Polibius(List<char> inputKey, List<char> inputAlphabet)
        {
            Alphabet = new List<List<char>>(5);
    
        List&lt;char&gt; distinctInputKey = inputKey.Distinct().ToList();
        for (int j = 0, i = 0; j &lt; sideOfSquare &amp;&amp; i &lt; distinctInputKey.Count; j++)
        {
            Alphabet[i].Add(distinctInputKey[j]);
            if (i % 5 == 0)
            {
                i++;
            }
        }
    }
    

    The entry and alphabet enter the function. Alphabet is stored in a matrix necessarily 5 * 5, in alphabet 25 unique symbols. I'm trying to write a matrix of alphabet so that the first lines are the letters from the inlet (without repetition), the other symbols are what's left in the alphabet. In the code, the compiler makes a mistake inside the cycle for additive operations (as all indices are 0). What's the mistake?

    P. S.: Is there a more beautiful solution to the recording of the word in the body (though it can be longer than 5 symbols).



  • Unlike C++, the designer's argument is Capacity, not Count. E. Alphabet is an empty list. And even if it was empty, every element of it would be null. We need to call up to 5 in the cycle. Alphabet.Add(new List<char>)


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2