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.

51: What does if((number <= 10) && (number >= 0)) evaluate to if number is -6?

A.   True

B.   False

52: Which keyword would be used in a class declaration to stop the class from being inherited?

A.   static

B.   extern

C.   out

D.   sealed

53: Which of the following is the correct way to write C# comments

A.   Both

B.   //

C.   /* */

D.   Neither

54: What is the keyword to create a condition in a switch statement that handles unspecified cases?

A.   else(...)

B.   if(...)

C.   default

D.   standard

E.   finally

55: Given the following statement: public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }. What is the value of Monday?

A.   0

B.   none of these

C.   1

D.   "Monday"

56: What is the purpose of the ref keyword in C#?

A.   It allows you to reference a variable value from anywhere inside of your program.

B.   It allows you to change the reference address of the variable.

C.   It allows you to pass a parameter to a method by reference instead of by value.

57: Which of the following describes a C# interface?

A.   An interface contains only methods and delegates.

B.   An interface contains only the signatures of methods, delegates or events.

C.   Interface is a keyword that allows classes to inherit from other classes.

D.   An interface is the UI presented to the user in an application.

E.   An interface allows you to define how a class will be named.

58: The C# statement: using System; means...

A.   create a namespace called system from the classes defined in this file.

B.   all of these

C.   import the collection of classes in the System namespace.

59: If you are overloading methods in a class the methods must have...

A.   none of these

B.   the same parameter types.

C.   the same number of parameters.

D.   the same name.

60: var x = default(DateTime); What is the expected value of "x" ?

A.   1/1/0001 12:00:00 AM

B.   0

C.   null

D.   Compiler error

E.   Exception will be thrown

61: When the protected modifier is used on a class member,

A.   no other class instances can access it.

B.   it becomes the default access for all members of the class.

C.   the member can be accessed by derived class instances.

62: Which classes are provided in C# for navigating through an XML file?

A.   XMLDocument

B.   None of these

C.   Both XMLDocument and XMLReader

D.   XMLReader

63: A static class in C# can only contain...

A.   both private and public members

B.   none of these

C.   both static and non-static members

D.   static members

64: Can you change the value of a variable while debugging a C# application?

A.   Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

B.   No, code gets "locked-down" during runtime.

65: How do you specify a reverse lambda expression

A.   (c =< c.Person)

B.   There is no such thing

C.   (c <= c.Person)

D.   ( c.Person <= c)

66: In C#, methods with variable number of arguments:

A.   can be created using the "..." signs in argument list

B.   can be created using the "params" keyword in argument list

C.   don't exist

67: Look at the following code: public delegate void EventHandler(); public static event EventHandler handler; static void Bar() { Console.WriteLine("Bar"); } Which of the following is a valid way to assign a new event handler?

A.   handler += new EventHandler(Bar);

B.   handler = new Event(Bar);

C.   handler += new Event(Bar);

D.   handler = new EventHandler(Bar);

68: Which of the following best describes this class definition? : public class Foo {}

A.   It is a class which contains one or more arrays

B.   This class extends the T class

C.   It is a generic class

D.   This class implements the T class

E.   None of these

69: bool test = true; string result = test ? "abc" : "def"; What is the value of result after execution?

A.   abcdef

B.   testabc

C.   abc

D.   def

E.   It doesn't compile.

70: Which attribute specifies a method to run after serialization occurs?

A.   OnDeserialized

B.   OnSerializing

C.   OnSerialized

D.   OnDeserializing

71: c => c.name == "Ben" Is an example of:

A.   LINQ

B.   Dynamic Typing

C.   Generics

D.   A Lambda Expression

72: What is unique about an abstract class in C#?

A.   You can only instantiate a reference to it.

B.   You cannot create an instance of it.

C.   You cannot inherit another class from it.

73: If your C# class is a static class called OutputClass, which contains public static void printMsg();, how would you call printMsg?

A.   OutputClass.printMsg();

B.   OutputClass oc = new OutputClass(); oc.printMsg();

C.   Both of these

74: What is the full name of the type that is represented by keyword int?

A.   System.Int64

B.   System.Int32

C.   System.Math.Int32

D.   System.Int

E.   Int32

75: What happens with the following lines? #region Debug [block of code HERE] #endregion

A.   The entire block of code is commented.

B.   The entire block of code is executed just in debug mode.

C.   You can visually expand or collapse the block of code.

76: In C# the System.String.Format method is used for ....

A.   Replacing the format item in a specified string with the string representation of a corresponding object.

B.   Coloring a input string with different colors to be used for text visualization.

C.   Making the specified string wordwrapped for text visualization.

D.   Prettifying code snippets.

E.   Automatically formatting decimals into a currency string representation. Ex: 1000 becomes $1 000

77: How do we instantiate generic list of objects

A.   myList = new List<Object>();

B.   myList = new List<Object>;

C.   myList = new List<typeof(Object)>();

D.   myList = new List<>(Object);

78: An interface contains signatures only for

A.   all of these

B.   events

C.   methods

D.   indexers

E.   properties

79: Which keyword is needed to compile a method in Csharp which uses pointers?

A.   static

B.   void

C.   unsafe

80: During the class definition, inheritance in C# is acomplished by putting which of the following:

A.   keyword "extends"

B.   ":" sign

C.   all of the answers are correct

D.   keyword "inherits"

81: Which of the following symbols allows the creation of verbatim string literals

A.   @

B.   ~

C.   ^

D.   `

E.   #

82: When the public modifier is used on a class,

A.   no other classes can access it inside of your program.

B.   the class can be accessed by external dll's.

C.   it becomes the default access for all classes in your program.

83: Reflection is used to...

A.   discover types and methods of assemblies on a user's machine.

B.   all of these

C.   viewing metadata.

D.   dynamically invoking methods on a user's machine.

84: The extern keyword is used to declare a method which is...

A.   implemented within the current project.

B.   implemented externally.

C.   implemented within one of the C# System classes.

85: C# code is compiled in...

A.   x86, x64 specific native code (or both), depending on compilation options

B.   Common Intermediate Language, compiled in CPU-specific native code the first time it's executed.

C.   Neutral bytecode, executed by the .Net virtual machine.

86: Which of the following declares your Csharp class as an attribute?

A.   public class myAttribute as System.Attribute

B.   public class myAttribute

C.   public class myAttribute : System.Attribute

87: In CSharp, what is the default member accessibility for a class?

A.   private

B.   protected

C.   public

88: In the following array instantiation: string[] names = new string[2]; , how many items can the array hold?

A.   1

B.   3

C.   0

D.   2

89: How do you catch an exception indicating that you are accessing data outside of the bounds of the array?

A.   catch(ArrayTypeMismatchException ex)

B.   catch(InsufficientExecutionStackException ex)

C.   catch(IndexOutOfRangeException ex)

D.   catch(ArrayIndexOutOfBounds ex)

90: How does a struct differ from a class in C# ?

A.   A class can be stored as either a reference or a value.

B.   A struct can contain implementation inheritance.

C.   A struct stores the value not a reference to the value.

91: The [Flags] attribute indicates that an enum is to be used as a bit field. However, the compiler will allow you to use an enum as a bit field, even without the [Flags] attribute.

A.   true

B.   false

92: Which of the following is not a C# keyword?

A.   is

B.   as

C.   of

D.   if

E.   in

93: Which is an example of a C# main method?

A.   all of these

B.   none of these

C.   static void Main()

D.   static int main()

94: Lambda expressions can be used a short form way to:

A.   Create generic types

B.   Assign a value to a delegate

95: Can you have a nullable DateTime in C#?

A.   No

B.   Yes

96: How do you implement your own version of ToString() method in your class?

A.   public string ToString() { }

B.   public override string ToString() { }

C.   public virtual string ToString() { }

D.   private override string ToString() { }

E.   public override ToString() { }

97: In order for the following to compile: using (CustomClass = new CustomClass()) { } CustomClass needs to implement which interface?

A.   ICustomAdapter

B.   IUsing

C.   IMemoryManagement

D.   IDisposable

E.   Disposable

98: The following line of code in C#: IEnumerable aList = new List();

A.   Illegal because List does not implement IEnumerable interface

B.   Illegal because the constructor of List cannot be empty

C.   Legal

D.   Illegal because it is not allowed to create an object of interface type

99: What is the default visibility for members of classes and structs in C#?

A.   private

B.   internal

C.   protected

D.   public

100: C# provides an XML documentation comment syntax by prefacing your comment lines with...

A.   ///

B.   <!--

C.   //