Why are boolean values converted to string in the case Camel in C#?

Asked

Viewed 60 times

3

Today I came across a peculiarity of C# which I had never stopped to pay attention to:

When converting a value bool for string, the result is a text in Camel case:

string verdadeiro = true.ToString(); //Converte para True
string falso = false.ToString(); //Converte para False

However, to use the literal values in the language, you need to write them in low box, write them in Camel case causes build error:

bool verdadeiro = True; //Não compila
bool falso = False; //Não compila

What is the reason for this difference?

  • Don’t you think only those who made the language can answer that?

  • Certainly a thorough knowledge of language is needed...

  • It’s not a matter of knowledge, it’s a matter of design, did so and it is so. The reasons behind this only those who decided can answer.

  • Do you have a question that is irrelevant to the community? If it is the opinion of the other moderators, may I remove it.

  • I’m not a moderator and I just asked a question.

  • I know, I think your question is relevant, so I left open the possibility of eliminating the question if it doesn’t add any relevant knowledge to the community.

Show 1 more comment

1 answer

3


This is the decision of the creators of language and framework, has nothing specific.

The name returned as string uppercase is a common form of use, if you need different it is easy to manipulate the way you want it.

The keyword in lowercase is consistent with the rest of the language which is all in lowercase, there would be because these literals are different from that.

Textual representation is something other than value in code.

  • Even, there are the case versions for reserved words of primitive type, such as String, Boolean, Int32, etc. I also do not know the origin of this in C# and would be curious to know.

  • 3

    This is because these are the names of the types in . NET in general, in C# an alias is used. Also a decision of design, most likely is C’s "inheritance".

  • 1

    Not exactly, there are types of framework written thus, reserved words are always in lowercase.

  • I always figured it had something to do with VB’s inheritance.

  • 4

    C# does not descend from VB.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.