What is the output of this C# code snippet?
using System; class Program { static void Main() { int myVariable = 5; int MyVariable = 10; Console.WriteLine(myVariable + ", " + MyVariable); } }
Remember that C# is case-sensitive when it comes to variable names.
C# treats myVariable and MyVariable as two different variables because it is case-sensitive. So, the output prints their values separated by a comma.
Which of the following is the correct naming convention for a constant in C#?
Constants in C# are usually declared with const keyword and use PascalCase.
In C#, constants are declared with the const keyword and follow PascalCase naming convention, so MaxSize is correct.
Which option violates the standard C# naming conventions for methods?
Methods in C# should use PascalCase without underscores.
Option B uses camelCase (calculateTotal) which is not the standard for methods in C#. Methods should use PascalCase.
Which of the following variable names will cause a syntax error in C#?
Variable names cannot start with a digit in C#.
Option C starts with a digit which is not allowed in C# variable names, causing a syntax error.
Given the following C# code, how many items will the dictionary contain after execution?
using System.Collections.Generic; var dict = new Dictionary<string, int>(); dict["FirstKey"] = 1; dict["firstkey"] = 2; dict["First_Key"] = 3; dict["FirstKey"] = 4;
Dictionary keys in C# are case-sensitive and exact string matches.
The dictionary keys are "FirstKey", "firstkey", and "First_Key" which are all different strings. The last assignment to "FirstKey" updates its value, so total items are 3.