Tell me, I read about such a variable type as

char 

It is written that this type can contain only 1 character, but the question is, where can I use it? After all, there is

 string 

It can take many values ​​at once ... so what is the benefit of using char ?

    1 answer 1

    String in its structure is an ordered collection of char objects (their array) and, generally speaking, String as a class provides convenient methods for working with this very collection.


    The char type itself is fundamentally necessary, because otherwise it would simply have been impossible to imagine the following entry:

     string s = "Здорово, Васек!"; // Каким типом данных представлять первую букву, если нет 'char'? ??? firstLetter = s[0]; 

    To summarize, it would be more likely to imagine C # without the String type, rather than the char type, since the String can be emulated as some IList<char> or IEnumerable<char> , etc.


    PS In fact, of course, the first paragraph is not entirely correct, given that the String behaves like a value type, not being it, but this is not so important to answer the question.

    • But then why, how many video lessons did I watch, did not mention this type of variable anywhere? (And I watched a lot of them) - Angus123
    • 6
      See less video tutorials and more write your programs. - toxicdream