Which of the following is NOT a valid identifier in C#?
A. _myVariable
B. 2ndVariable
C. My_Variable
D. myVariable_2
Answer: Option B
Solution (By Examveda Team)
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.
Join The Discussion