C# Question

Return the char value of null

This my code;

public void Dönüştür()
{
int TextboxLength = TextBox.MaxLength;
string LowerText = TextBox.Text.ToLower();
var AllCharacters = "";

for (int i = 0; i < TextboxLength; i++)
{
char Characters = char.Parse(LowerText);
switch (Characters)
{
case '0': AllCharacters += "0"; break;
case '1': AllCharacters += "1"; break;
case '2': AllCharacters += "2"; break;
case '3': AllCharacters += "3"; break;
case '4': AllCharacters += "4"; break;
case '5': AllCharacters += "5"; break;
case '6': AllCharacters += "6"; break;
case '7': AllCharacters += "7"; break;
case '8': AllCharacters += "8"; break;
case '9': AllCharacters += "9"; break;

case ' ': case '+': case '-': case '_': AllCharacters += "0"; break;
case ':': case ';': case '=': case ',': case '.': AllCharacters += "1"; break;
case 'a': case 'b': case 'c': case 'ç': AllCharacters += "2"; break;
case 'd': case 'e': case 'f': AllCharacters += "3"; break;
case 'g': case 'ğ': case 'h': case 'ı': case 'i': AllCharacters += "4"; break;
case 'j': case 'k': case 'l': AllCharacters += "5"; break;
case 'm': case 'n': case 'o': case 'ö': AllCharacters += "6"; break;
case 'p': case 'r': case 's': case 'ş': AllCharacters += "7"; break;
case 't': case 'u': case 'ü': AllCharacters += "8"; break;
case 'v': case 'y': case 'z': case 'x': case 'w': AllCharacters += "9"; break;
}

}
MessageBox.Show(TextBox.MaxLength.ToString(), "TextBox MaxLength:");
MessageBox.Show(AllCharacters.ToString(), "AllCharacters value:");
}


I want to convert the numbers to letters. The char value but it seems empty.

Like this

If checked, the TextBox is filled, although for loop does not work. The reason for this may be the number of characters of 0 TextBox but the TextBox is filled.

Like this

What the problem is, where am I making mistake?

Answer

You are looping for the number of times specified by TextBox.MaxLength, which is zero, so it doesn't loop at all. Did you mean to loop by TextBox.Text.Length?

The MaxLength property, if set to more than zero restricts the number of characters that may be entered into the textbox.

    for (int i = 0; i < TextBox.Text.Length; i++)
    {
         char Characters = LowerText[i];
         ...
    }
Comments