What does it mean (Char) 0 / (Char) 8 / (Char) 13?

0

I'm doing a shopping program and found it on that same site. The answer to a problem I had, but I did not understand what the (Char)0 part would be, among others. I need to explain what this is.

private void preVenda_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((e.KeyChar < '0' || e.KeyChar > '9') && 
         e.KeyChar != ',' && e.KeyChar != '.' && 
         e.KeyChar != (char)13 && e.KeyChar != (char)8)
    {
        e.KeyChar = (char)0;
    }
    else
    {
        if (e.KeyChar == '.' || e.KeyChar == ',')
        {
            if (!preVenda.Text.Contains(','))
            {
                e.KeyChar = ',';
            }
            else
            {
                e.KeyChar = (char)0;
            }
        }
    }
}

Here is the image:

    
asked by anonymous 25.11.2018 / 11:34

1 answer

1

And this do you understand?

'
'%pre%', '', ''
', '', ''
It's the same thing. Everything is number on the computer. The type char is only something that is conceptually treated with "letters" (characters) and when you do show it is already drawn as text, but the encoding of each character is a number following a table. C # uses UTF-16 encoding by default, but the bulk of the characters we use are from the ASCII table , so each number refers to one character, and not all are printable, some are special and have you do some specific action or determine something that is not printable, which is the case for everyone below code 32.

The 0 is null, the 8 is a tab, and the 13 is a line change. The backslash is an escape character, in the syntax of most languages, including C #, it indicates that the following is something special and should not be treated as a character but rather as a code from the encoding table or even some term special, for example 8 can be expressed as \t and 13 as \r , or in some cases as \n , but it depends on platform. It is necessary to do this just because they are not printable.

Since C # is a strong typing language it avoids mixing types and doing automatic promotions that can give some trouble, so you can not assign numbers or use as char pending directly, you have to explicitly ensure that that type being used is char , so a cast is done in the number only to tell the compiler that you know what you are doing and that number should be interpreted as a character.

    
25.11.2018 / 11:53