CommerceBasic Syntax And Data Types In C Sharp MCQs
Practice Basic Syntax And Data Types In C Sharp MCQs for competitive exams.
Basic Syntax And Data Types In C Sharp MCQs
Practice questions from this topic.
What will be the output of the following C# code? int a,b; a = (b = 10) + 5;
- A. b = 10, a = 5
- B. b = 15, a = 5
- C. a = 15, b = 10
- D. a = 10, b = 10
Correct Answer: C
For two strings s1 and s2 to be equal, which is the correct way to find if the contents of two strings are equal?
- A. if(s1 = s2)
- B. int c; c = s1.CompareTo(s2)
- C. if (s1 is s2)
- D. if(strcmp(s1, s2))
Correct Answer: B
Storage location used by computer memory to store data for usage by an application is?
- A. Pointers
- B. Constants
- C. Variable
- D. None of the mentioned
Correct Answer: C
For the following C# code select the relevant solution for conversion of data type. static void Main(string[] args) { int num1 = 20000; int num2 = 50000; long total; total = num1 + num2; Console.WriteLine("Total is : " +total); Console.ReadLine(); }
- A. Compiler will generate runtime error
- B. Conversion is implicit type, no error generation
- C. Specifying data type for conversion externally will solve the problem
- D. None of the mentioned
Correct Answer: B
What will be the output of the following C# code? class Program { static void Main(string[] args) { int i; for ( i = 0; i < 5; i++) { } Console. WriteLine(i); Console. ReadLine(); } }
- A. 0, 1, 2, 3, 4, 5
- B. 0, 1, 2, 3, 4
- C. 5
- D. 4
Correct Answer: C
Syntax for declaration and initialization of data variable is?
- A. =
- B.
- C.
- D. =
Correct Answer: A
Choose ".NET class" name from which data type "UInt" is derived?
- A. System.Int16
- B. System.UInt32
- C. System.UInt64
- D. System.UInt16
Correct Answer: B
Type of Conversion in which compiler is unable to convert the data type implicitly is?
- A. ushort to long
- B. int to uint
- C. byte to decimal
- D. None of the above
Correct Answer: B
What is the correct way to declare and initialize a string variable in C#?
- A. string = str
- B. str Hello
- C. str = "Hello"
- D. string str = "Hello"
Correct Answer: D
What is the output of the following code: Console.WriteLine($"5 + 5 = {5 + 5}");
- A. 5 + 5 = 10
- B. 10
- C. $"5 + 5 = {5 + 5}"
- D. Compilation error
Correct Answer: A
What is the purpose of the 'unchecked' keyword in C#?
- A. Enables overflow checking
- B. Terminates the program
- C. Compiles the program without errors
- D. Disables overflow checking for integral-type arithmetic operations
Correct Answer: D
What is the correct syntax to declare a nullable integer variable in C#?
- A. nullable int num
- B. var? num
- C. int? num
- D. num? int
Correct Answer: C