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.
Which is the String method used to compare two strings with each other?
- A. Compare To()
- B. Compare()
- C. Copy()
- D. ConCat()
Correct Answer: B
Choose the correct type of variable scope for the following C# defined variables. class ABC { static int m; int n; void fun (int x , ref int y, out int z, int[] a) { int j = 10; } }
- A. m = static variable, n = local variable, x = output parameter, y = reference parameter, j = instance variable, z = output parameter, a[0] = array element
- B. m = static variable, n = instance variable, x = value parameter, y = reference parameter, j = local variable, z = output parameter , a[0] = array element
- C. m = static variable, n = instance variable, x = reference parameter, y = value parameter, j = local variable, z = output parameter, a[0] = array element
- D. m = local variable, n = instance variable, x = reference parameter, y = value parameter, j = static variable, z = output parameter, a[0] = array element
Correct Answer: B
What will be the output of the following C# code? static void Main(string[] args) { { var dayCode = "MTWFS"; var daysArray = new List(); var list = new Dictionary { {"M", "Monday"}, {"T", "Tuesday"}, {"W", "Wednesday"}, {"R", "Thursday"}, {"F", "Friday"}, {"S", "Saturday"}, {"U", "Sunday"} }; for (int i = 0,max = dayCode.Length; i < max; i++) { var tmp = dayCode[i].ToString(); if (list.ContainsKey(tmp)) { daysArray.Add(list[tmp]); } } Console.WriteLine(string.Join("n ", daysArray)); }
- A. Monday, Tuesday, Wednesday, Friday, Saturday, Sunday
- B. Monday Tuesday Wednesday Friday Sunday
- C. Monday Tuesday Wednesday Friday Saturday
- D. Monday, Tuesday, Wednesday, Friday, Saturday
Correct Answer: C
What will be the output of the following C# code? static void Main(string[] args) { string s1 = "Delhi"; string s2; s2 = s1.Insert (6, "Jaipur"); Console.WriteLine(s2); }
- A. DelhJaipuri
- B. Delhi Jaipur
- C. Delhi
- D. DelhiJaipur
Correct Answer: D
'Implicit Conversion' follows the order of conversion as per compatibility of data type as:
- A. float < char < int
- B. char < int < float
- C. int < char < float
- D. float < int < char
Correct Answer: B
What will be the output of the following C# code? static void Main(string[] args) { float a = 10.553f; long b = 12L; int c; c = Convert.ToInt32(a + b); Console.WriteLine(c); }
- A. 23.453
- B. 22
- C. 23
- D. 22.453
Correct Answer: C
What will be the output of the following C# code? public static void Main(string[] args) { int i = 546; object o = i; int n =(int) o; o = 70; System. Console. WriteLine("The value-type value = {0}", n); System. Console. WriteLine("The object-type value = {0}", o); Console. ReadLine(); }
- A. 546, 0
- B. 546, 546
- C. 546, 70
- D. 70, 546
Correct Answer: C
Correct statement about strings are?
- A. a string is created on the stack
- B. a string is primitive in nature
- C. a string created on heap
- D. created of string on a stack or on a heap depends on the length of the string
Correct Answer: C
Correct way to assign values to variable 'c' when int a=12, float b=3.5, int c;
- A. c = a + b
- B. c = a + int(float(b))
- C. c = a + convert.ToInt32(b)
- D. c = int(a + b)
Correct Answer: C
Correct way to define a value 6.28 in a variable 'pi' where value cannot be modified?
- A. #define pi 6.28F
- B. pi = 6.28F
- C. const float pi = 6.28F
- D. const float pi pi = 6.28F
Correct Answer: C
For the given set of C# code, is conversion possible? static void Main(string[] args) { int a = 76; char b; b = (char)a; Console.WriteLine(b); Console.ReadLine(); }
- A. Compiler will generate runtime error
- B. Conversion is explicit type
- C. Compiler will urge for conversion from 'integer' to 'character' data type
- D. None of the mentioned
Correct Answer: B
Which Conversion function of 'Convert.TOInt32()' and 'Int32.Parse()' is efficient? i. Int32.Parse() is only used for strings and throws argument exception for null string ii. Convert.Int32() used for data types and returns directly '0' for null string
- A. ii
- B. Both i, ii
- C. i
- D. None of the mentioned
Correct Answer: A