C# Interview Questions - 7 | Snaprecruit.com

C# Interview Questions - 7 | Snaprecruit.com

C SHARP interview questions part 7

C SHARP interview questions part 7

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which among the following statements are not correct about a namespace used in C#.NET?

Correct Answer is : constructor

2. Which among the following is the correct statement about the using statement used in C#.NET?

Correct Answer is : 9 8 7 6 5 4 3 2 1

3. What will be the output of the following code snippet? #define DEBUG #undef DEBUGusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace ConsoleApplication13{ class Program { static void Main(string[] args) { #if (DEBUG) Console.WriteLine("DEBUG is defined"); #elif (!DEBUG && MYTEST) Console.WriteLine("MYTEST is defined"); #elif (DEBUG && MYTEST) Console.WriteLine("DEBUG and MYTEST are defined"); #else Console.WriteLine("DEBUG and MYTEST are not defined"); #endif Console.ReadLine(); } }}

Correct Answer is : Compile time error

4. For the code set given below,which of the following statements are perfectly valid? public class MyContainer where T: class, IComparable{ /* insert code here */}

Correct Answer is : Test-Your-C#.NET-Skills

5. Which of given statements are valid about generics in .NET Framework?

Correct Answer is : All of the mentioned

6. Which of the following is a valid statement about generic procedures in C#.NET are?

Correct Answer is : All of the mentioned

7. For the code set given below,which of the following statements are perfectly valid? public class MyContainer where T: IComparable{ /* insert code here */}

Correct Answer is : Test Your C#.NET Skills

8. Choose the statements which are valid for given code snippet: public class Generic{ public T Field; public void testSub() { T i = Field + 1; }}class Program{ static void Main(string[] args) { Genericg = new Generic(); g.testSub(); }}

Correct Answer is : Only one method can be called using a delegate

9. Which among the given classes represents System.Collections.Generic namespace?

Correct Answer is : all of the mentioned

10. What will be the output of the given code snippet? public class Generic{ Stack stk = new Stack(); public void push(T obj) { stk.Push(obj); } public T pop() { T obj = stk.Pop(); return obj; }}class Program{ static void Main(string[] args) { Generic g = new Generic(); g.push(30); Console.WriteLine(g.pop()); Console.ReadLine(); }}

Correct Answer is : ~

11. What will be the output of the given code snippet? public class Generic{ Stack stk = new Stack(); public void push(T obj) { stk.Push(obj); } public T pop() { T obj = stk.Pop(); return obj; }}class Program{ static void Main(string[] args) { Generic g = new Generic(); g.push("C++"); Console.WriteLine(g.pop() + " "); Generic g1 = new Generic(); g1.push(20); Console.WriteLine(g1.pop()); Console.ReadLine(); }}

Correct Answer is : Dispose()

12. Select the output for the following set of code : static void Main(string[] args) { int i = 30; int j = 25 % 25; if (Convert.ToBoolean(Convert.ToInt32(i = j))) { Console.WriteLine("In if"); } else { Console.WriteLine("In else"); } Console.WriteLine("In main"); Console.ReadLine(); }

Correct Answer is : Destructor

13. Select output for the following set of Code: static void Main(string[] args) { int i; int b = 8, a = 32; for (i = 0; i <= 10; i++) { if ((a / b * 2)== 2) { Console.WriteLine( i + " "); continue; } else if (i != 4) Console.Write(i + " "); else break; } Console.ReadLine(); }

Correct Answer is : Both There is one common garbage collector for all programs & To garbage collect an object set all references to it as null

14. Select the output for the following set of code : static void Main(string[] args) { int i, j; for (i = 2; i >= 0; i--) { for (j = 0; j <= 2; j++) { if (i == j) { Console.WriteLine("1"); } else { Console.WriteLine("0"); } } Console.WriteLine("\n"); Console.ReadLine(); } }

Correct Answer is : delete

15. Select the correct ‘if statement’ to be filled in the given set of code : static void Main(string[] args) { int []num = {50, 65, 56, 88, 43, 52}; int even = 0, odd = 0; for (int i = 0 ;i < num.Length ;i++) { /*___________________________*/ } Console.WriteLine("Even Numbers:" +even); Console.WriteLine("Odd Numbers:" +odd); Console.ReadLine(); }

Correct Answer is : Destructors can have modifiers or parameters

16. Select the output for the following set of Code : static void Main(string[] args) { int a = -1; int b = -1; if (Convert.ToBoolean (++a = ++b)) Console.WriteLine("a"); else Console.WriteLine("b"); Console.ReadLine(); }

Correct Answer is : Compile time error

17. Select the output for the following set of Code : static void Main(string[] args) { int a = 5, b = 10; if (Convert.ToBoolean(Convert.ToInt32(0xB))) if (Convert.ToBoolean(Convert.ToInt32(022))) if (Convert.ToBoolean(Convert.ToInt32('\xeb'))) Console.WriteLine("java"); else ; else ; else ; }

Correct Answer is : 180

18. Select the output for the following set of Code : static void Main(string[] args) { int a = 5, b = 10; if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b))) { Console.WriteLine(a + "\n" + b); } else Console.WriteLine(" C# "); }

Correct Answer is : True True True

19. What will be the output of the following set of code? { int sum = 10; try { int i; for (i = -1; i < 3; ++i) sum = (sum / i); } catch (ArithmeticException e) { Console.WriteLine("0"); } Console.WriteLine(sum); Console.ReadLine(); }

Correct Answer is : -0.04999995

20. What will be the output of the following set of code? { try { int []a = {1, 2, 3, 4, 5}; for (int i = 0; i < 5; ++i) Console.WriteLine(a[i]); int x = (1 / Convert.ToInt32(0)); } catch(IndexOutOfRangeException e) { Console.WriteLine("A"); } catch(ArithmeticException e) { Console.WriteLine("B"); } Console.ReadLine();}

Correct Answer is : 45437

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon