Vidyalelo
C# Programming · Q8

Introduction to C Sharp

Programming · C# Programming · question 8

Q8

Which of the following is NOT a valid identifier in C#?

A.
_myVariable
B.
2ndVariable
Answer
C.
My_Variable
D.
myVariable_2

Answer: Option B

Solution

Answer: Option B
Solution:
Identifiers in C# are names given to variables, methods, classes, etc.

Valid identifiers in C# can include letters (a-z, A-Z), digits (0-9), and underscores (_), but they cannot start with a digit.

Option A: _myVariable - This is a valid identifier because it starts with an underscore and follows the rules.

Option B: 2ndVariable - This is an invalid identifier because it starts with a digit, which is not allowed in C# identifiers.

Option C: My_Variable - This is a valid identifier as it follows the rules.

Option D: myVariable_2 - This is a valid identifier as it follows the rules.

Therefore, the correct answer is Option B: 2ndVariable.