C# MCQs

C# MCQs

Answer these 700+ C# MCQs and see how sharp is your knowledge of C#. Scroll down and let's start!

1: Which statement do you use to stop loop processing without a condition?

A.   break;

B.   continue;

C.   jump;

2: In C# 6 which of the following features is used to cut down on the code written to check for null values in a nested object.

A.   <IsNullable>

B.   ?.

C.   inline declaration for out params

3: What is a jagged array in C#?

A.   A multi-dimensional array with dimensions of various sizes.

B.   A multi-dimensional array with dimensions of the same size.

C.   An array of singular dimension with an unknown size.

4: Which of the following is not a bitwise operator

A.   #

B.   ^

C.   |

D.   &

5: Exceptions can be handled in Csharp with a...

A.   none of these

B.   Throw Exception

C.   try catch finally block

D.   ON ERROR Resume NEXT statement

6: How can you access the first element from the following array int[] x = {1,2,3};

A.   x[1]

B.   x.First

C.   x[0]

7: In order to create a filestream object in C#, what do you need to include in your program?

A.   using System.Strings

B.   using System.IO;

C.   #include <System.IO>

8: Which of the following constructs are used to handle errors in C#?

A.   try, catch, finally

B.   Garbage Collection

C.   the using statement

D.   try, catch, deconstruct

9: Choose the types of members which you can have in your C# class?

A.   methods

B.   constructors

C.   fields

D.   all of these

10: Exceptions can be handled in C# with a...

A.   try catch finally block

B.   none of these

C.   Throw Exception

D.   ON ERROR Resume NEXT statement

11: Which of the following is the recognised file extension for C# files

A.   .csx

B.   .cs

C.   .c#

D.   .cpp

E.   .c

12: Given the following C# statement: int[] myInts = { 5, 10, 15 }; What is the value of myInts[1]?

A.   15

B.   10

C.   5

13: If your Csharp class is called Cats, which statement creates an object of type Cats?

A.   Cats myCat = new cats();

B.   cats myCat = new cats();

C.   Cats myCat = new Cats();

14: Which C# debugging tools are available to you with Visual Studio?

A.   Stepping through your code

B.   All of these

C.   Breakpoints

15: What is used in C# to terminate a statement?

A.   ellipsis

B.   semi-colon

C.   period

D.   colon

16: In C#, what would you use to output the contents of a variable to the screen?

A.   Console.Write() method

B.   System.Write() method

C.   Console.Print() method

17: What type of memory management does Csharp employ?

A.   managed

B.   manual allocation

18: True or false: A class can implement multiple interfaces

A.   False

B.   True

19: The purpose of the curly braces, { and }, in C#:

A.   is to delineate the end of a statement to be executed.

B.   is to mark the beginning and end of a logical block of code.

C.   is to mark function code to be used globally.

D.   None of these

20: Which of the following is not a built-in data type in C#?

A.   int

B.   bool

C.   string

D.   single

21: A sealed class in C# means:

A.   derived classes can override some of the class methods.

B.   that you can create objects of that class type.

C.   that the class cannot be used for inheritance.

22: The manifest of a C# assembly contains...

A.   all of these

B.   version information.

C.   supported locales.

23: Which of the following symbols is used to concatenate strings

A.   +

B.   &

C.   &&

D.   *

E.   ^

24: Csharp provides a built in XML parser. What line is needed to use this feature?

A.   using System.Xml;

B.   using System.Strings

C.   using System.Parser

D.   using System;

25: Can you have a single Try clause with multiple catch clauses?

A.   Yes

B.   No

26: What would the following code snippet print out: string x = "test"; string y = "hello"; Console.WriteLine("{0}, this is a {1}", x, y);

A.   This would not compile

B.   hello, this is a test

C.   test, this is a hello

D.   {0}, this is a {1}

27: An Indexer in C# allows you to index a

A.   struct

B.   Both class and struct

C.   class

28: What is the purpose of the following statement: ~myClass() ?

A.   It is the destructor for myClass instances.

B.   It is a property called myClass.

C.   It is a constructor for myClass instances.

29: what does the expression !false evaluate to

A.   Run time error

B.   1

C.   true

D.   Compile time error

E.   false

30: Which statement is a convenient way to iterate over items in an array?

A.   foreach

B.   for

C.   switch

31: C# support what types of inheritance.

A.   All options.

B.   Interface inheritance

C.   Implementation inheritance

32: The keyword used to include libraries/namespaces in C# is:

A.   include

B.   import

C.   use

D.   using

33: Where would you find the definition for the Stack class?

A.   System.Collections.Generic namespace

B.   System.Data namespace

C.   System.Collections.Specialized namespace

34: CSharp cannot be run without installing...

A.   all .NET languages.

B.   the Common Language Runtime.

C.   the Java Virtual Machine.

35: Which classes are provided in C# for writing an XML file?

A.   XMLReader

B.   XMLCreation

C.   XMLWriter

36: If you have a C# program containing a runtime error and a compile time error, which would you first be alerted to on compilation?

A.   Run Time Error

B.   Both

C.   Neither

D.   Compile Time Error

37: What is the following code similar to Object.Equals(Person, null)

A.   Person<Nullable>

B.   Person == null

C.   Person.Null

D.   Person?

38: What is the result of the following expression? int x = 100 / 0;

A.   The system will throw a MathFormatException

B.   x = null;

C.   The system will throw a InvalidOperationException

D.   The system will throw a DivideByZeroException

E.   x = NaN;

39: The Code Document Object Model can be used for...

A.   all of these

B.   allowing developers to create their own code generation utilities.

C.   developing automatic source code generators.

40: The default value of a reference type is...

A.   0

B.   null

C.   unknown

D.   none of these

41: Which class provides the best basic thread creation and management mechanism for most tasks in Csharp?

A.   System.Runtime.Serialization

B.   System.Threading.ThreadPool

C.   System.IO.Compression

42: Which of the following is an example of dot notation

A.   Person == true ? Employee: Manager

B.   Person.Name;

C.   Person ?? Employee

43: What are the access modifiers available in C#?

A.   public, protected, internal, private

B.   public, private

C.   public, protected, private

D.   public, internal, private

E.   protected, internal, private

44: Which option below is an Operator?

A.   Ternary

B.   Unary

C.   Binary

D.   All Options

45: C# is based on which of the following languages

A.   Java

B.   Ruby

C.   Python

D.   Javascript

E.   C

46: Identifiers in C# are case sensitive

A.   false

B.   true

47: Classes that can be used for reading / writing files like TextReader, StreamWriter, File can be found in which namespace?

A.   System.Text

B.   System.DataAnnotations

C.   System.Data

D.   System.IO

E.   System.Stream

48: Valid parameter types for Indexers in C# are...

A.   all of these

B.   integer

C.   string

D.   enum

49: You can attach a handler to an event by using which operator?

A.   =>

B.   ++

C.   +=

D.   =

E.   ->

50: If you know that a method will need to be redefined in a derived class,

A.   you should declare it as private in the base class.

B.   you should declare it as virtual in the base class.

C.   you should declare it as partial in the base class.