?
Which of the following is NOT a valid identifier in C#?
Answer & Solution
Correct Answer:
Option
B
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.
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
Login to post a comment or share your explanation.
Login