Explore 30 MCQs on C# Basic Syntax and Data Types, covering syntax, data types (value and reference), type conversions, casting, and more. Strengthen your foundation in C# programming with these questions.
.;:,int x = 1010 + 20if (x > 10)using directive in C#?
var x = 10;x = 10;int x = 10declare x as int// This is a comment/* This is a comment */<!-- This is a comment -->/* comment */// comment<!-- comment --># comment// comment# comment/* comment */<!-- comment -->if (x > 10) { }if x > 10 { }if { x > 10 }if (x > 10) : { }Console.WriteLine() method do in C#?int type in C#?0nullfalse"" (empty string)bool variable in C#?bool isTrue = true;boolean isTrue = true;bool isTrue = "true";boolean isTrue = "true";string keyword represent in C#?char data type represent in C#?int[] arr = new int[5];int arr[5];array<int> arr = new array<int>(5);arr = new int[5];int x = 10; double y = x;double x = 10.5; int y = (int)x;float x = 10.5; string y = (string)x;char x = 'a'; int y = (int)x;double value to an int without casting?double will be converted to a string(type)Convert.ToType() methodint() methodparse() functionConvert.ToInt32() method in C#?double to intdouble to an int with truncation in C#?null reference type to any value type in C#?null will be converted to 0null will be automatically boxedstringConvert.ToInt32()int.Parse()int.TryParse()int.Convert()| Qno | Answer |
|---|---|
| 1 | b) ; |
| 2 | d) All of the above |
| 3 | a) To import namespaces |
| 4 | c) int x = 10 |
| 5 | d) Both a and b |
| 6 | a) To write descriptions and explanations in the code |
| 7 | b) // comment |
| 8 | c) /* comment */ |
| 9 | a) if (x > 10) { } |
| 10 | a) Prints a message to the console |
| 11 | b) int |
| 12 | a) 0 |
| 13 | a) bool isTrue = true; |
| 14 | b) double |
| 15 | b) char |
| 16 | c) decimal |
| 17 | a) Reference type |
| 18 | a) A single character from the ASCII table |
| 19 | a) int[] arr = new int[5]; |
| 20 | c) string |
| 21 | a) Implicit casting happens automatically, explicit casting requires a cast operator |
| 22 | a) int x = 10; double y = x; |
| 23 | a) It will result in a compile-time error |
| 24 | a) By using the cast operator (type) |
| 25 | a) It converts a value to an integer type |
| 26 | a) A value type is converted to a reference type |
| 27 | a) Converting a reference type back into a value type |
| 28 | b) Explicit casting |
| 29 | a) It will result in a runtime exception |
| 30 | c) Using int.TryParse() |