Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Identificadores | Primeros Pasos
Quizzes & Challenges
Quizzes
Challenges
/
Fundamentos de C#

bookIdentificadores

In C#, all variables must have unique names. These unique names are called identifiers as they identify the different variables.

There are certain rules for naming variables. Following are the rules that one must keep in mind when naming a variable:

  • Variable names can contain lowercase letters (a-z), uppercase letters (A-Z), numbers (0-9) and the underscore symbol (_). Any other character is invalid;
  • Variable names cannot begin with a number. They can begin with a letter or an underscore;
  • Variable names cannot contain whitespace (space);
  • A variable name cannot be the same as a reserved word. Reserved words are predefined keywords that have a specific meaning or function in a programming language. Some examples of reserved words are: var, namespace, class, internal, etc;
  • Variable names are case sensitive, therefore the name myVar does not conflict with MyVar.

Examples of Valid and Invalid Variable Names

Valid Examples:

  • myVariable;
  • My_Variable;
  • _myVariable;
  • variable1.

Invalid Examples:

  • 1variable (starts with a number);
  • my variable (contains whitespace);
  • class (reserved word).
question mark

Which of the following variable names are INVALID ?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 8

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Suggested prompts:

Can you give more examples of reserved keywords in C#?

What are some tips for choosing good variable names?

Can you explain the difference between camelCase and PascalCase?

bookIdentificadores

Desliza para mostrar el menú

In C#, all variables must have unique names. These unique names are called identifiers as they identify the different variables.

There are certain rules for naming variables. Following are the rules that one must keep in mind when naming a variable:

  • Variable names can contain lowercase letters (a-z), uppercase letters (A-Z), numbers (0-9) and the underscore symbol (_). Any other character is invalid;
  • Variable names cannot begin with a number. They can begin with a letter or an underscore;
  • Variable names cannot contain whitespace (space);
  • A variable name cannot be the same as a reserved word. Reserved words are predefined keywords that have a specific meaning or function in a programming language. Some examples of reserved words are: var, namespace, class, internal, etc;
  • Variable names are case sensitive, therefore the name myVar does not conflict with MyVar.

Examples of Valid and Invalid Variable Names

Valid Examples:

  • myVariable;
  • My_Variable;
  • _myVariable;
  • variable1.

Invalid Examples:

  • 1variable (starts with a number);
  • my variable (contains whitespace);
  • class (reserved word).
question mark

Which of the following variable names are INVALID ?

Select the correct answer

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 8
some-alt