100 C# "C Sharp" Interview Questions To Hire Or Get Hired With

C, as a computing language is one of the first ever invented. It is widely classified as a programming language which is tied to native software applications. This means applications which you install natively on your laptop or desktop computer to run with or without the use of the internet. It was developed by Microsoft within its .NET facework initiative and then later approved as a standard ECMA programming language. C# was developed by a team led by Ander Hejlsberg in 2002. It is widely associated with Visual Studio, which is also a Microsoft product. C# (or C Sharp) first appeared nearly 18 years ago. It is a variation on the C core programming language. It is intended to be suitable for writing hosted and embedded software programs ranging from being the backbone of very large and quite sophisticated operating systems down to single task-oriented functions for users of all kinds. You will often see C# (or C Sharp) associated to custom business software development requests as it can be an on-prem solution, which means it is a function only accessed by those who have a work computer that is either in a secured office or secured by remote viewing.

1. Describe what you understand of C# (or C Sharp) and its features?

C# is the best language for writing Ms.NET applications by providing rapid application development found in Visual Basic and powered by C++. C# syntax is almost similar to that of C++. The main functions of C# are as follows.

• It is object oriented, type safe and managed language
• It enables developers to compile and work with .Net framework to generate Microsoft intermediate language

Features of C#
• Properties
• Passing parameters
• Constructors and deconstructions
• Arrays
• Main
• XML documentation
• Indexers

1B. What are the pros of C#?

• It is easy to learn
• It is object-oriented
• Component-oriented
• It is linked .NET framework
• It supports various operating systems
• Developers who understand the language will start working on C# within a short time

2. State types of comments in C# and give examples

• Single line
Example: // this is a Single line comment
• Multiple line (/**/)
Example: /* this is multiple line comment
We are in line 2
Last lie of comment */
• XML comments (///)
Example: /// summary;
/// Set error message for multilingual language.
/// summary.

3. Describe an object?

• An object is a block that has been allocated and configured according to the blueprint. A developer can have a program that creates many objects of the same class. The objects might also be referred to as instances, and they might be stored in a named variable, an array or in a collection.

4. What is a class?

• This is an encapsulation of properties and methods that are used to come up with a real-time product. It is a data structure that brings all the instances together into a single unit.

• A class that is used to create an object will contain all the information regarding the methods, variables, and behaviors of the class.

5. What is an object-oriented language?

• This is a language that supports concepts of encapsulation, inheritance, and polymorphism.

• Object-oriented language supports programs that consist of multiple objects that interact dynamically.

6. Explain the fundamental object oriented programming concepts

• Encapsulation: in this concept internal representation of an object has hidden the view of outside objects definition. In this regard, only the required information can be accessed whereas the rest of data implementation is hidden.

• Abstraction: this is a process determining the critical behavior and information of an object and will not eliminate the irrelevant details.

• Inheritance: here the developers get an opportunity to create new classes from the other existing classes. Typically, this done by accessing, modifying and extending the behaviors of the objects in the parent class.

• Polymorphism: this is achieved by having multiple methods with the same name but different implementations.

7. Is it possible to execute multiple catch blocks?

• Multiple catch block cannot be executed.

• When the proper catch code is executed, the control is transferred to the final block and then the code that follows gets executed.

8. Differentiate between public static and void

• Public declared variables are accessible anywhere in the application

• Static declared variables and methods are globally accessible without creating an instance of the class. Ideally, the static members are by default not globally accessible it depends on the type of access modified used. The developer stores address of the method as the entry point and allows the information to begin execution before any objects are created.

• The void is a type modifier that states that method or variable does not return any value?

9. State the IDE’S provided by Microsoft for C# development

• Visual studio express (VCE)
• Visual studio (VS)
• Visual Web Developer

10. Explain constructors

• A constructor is a function in a class that has the same as its class.
• Typically, a constructor is automatically invoked whenever the object class is created. It constructs the values of data members while initializing the class.

11. What is sealed class in C#?

This is a class that has been developed in such a way that has capabilities to prevent the class from being inherited from other classes. It can be used to avoid the methods to override in the child classes.

12. Differentiate between ref and out parameters?

• Refs are arguments that must be initialized before passing the method

• The out parameters do not need to be initialized before passing to a method.

13. What are jagged arrays?

• This is an array that has elements of type array
• The elements of the jagged array can occur in different dimensions and sizes.
• Sometimes they are referred to as an array of arrays.

14. Why do developers use the "using statement" in C#?

The using block is utilized in getting a resource and uses it and then automatically disposes of when the execution of block is completed.

15. Describe serialization

• This occurs when developers transport an object through a network then they need to convert the object into a stream of bytes. The process of converting the object into stream bytes is what we call serialization.

• For an object to be serialized it should implement or serialize the interface.

16. Explain what an interface is

• Typically this is a class with no implementation.

• It only contains the declaration of methods, properties, and events.

17. Explain different types of classes that occur in C#?

• Partial class: the class allows its components to be divided and shared with multiple files. The class marked with the keyword Partial.

• Sealed class: its components and members cannot be inherited. In order to access the members of the sealed class, the developers have to create the object of the class. It is identified by keyword Sealed.

• Abstract class: in this class, the object cannot be instantiated. However, the class can be inherited. It contains at least one method and is identified with the keyword abstract.

• Static class is a class that cannot be inherited. The members of the class are static and the class is identified with the keyword static.

18. Explain how code compilation occurs in C#

Compilation occurs through the following steps:
• Compiling the source code into managed code using the C# compiler.
• Building the newly created codes into assemblies.
• Loading the Common Language Runtime (CLR)
• Executing the assembly by CLR.

19. Differentiate between an array and an array list?

• An array serves as a storage or related values and elements while the array list stress values of different data types.

• Arrays utilize fixed length but the array list does not use fixed length.

20. Explain the difference between a struct and a class in C#

• Both are user-defined but they have some distinct differences:
• A struct is value type and inherits from System. Value Type
• Struct can’t be inherited to other types
• A structure can be abstract
• Instruct the object is never created using the keyword.
• The developer does not have permission to create any default constructor.
• On the contrary, a class is a reference type in C# and it inherits from System. Object Type.
• Classes are utilized to handle large volumes of data
• A class has the capability to be inherited to other classes
• A class can occur as an abstract in type.
• It is impossible to use an object of a class without using new keyword.
• With a class, it is possible to develop a default constructor.

21. Explain the difference between an interface and abstract class

• A class has the capability of implementing many interfaces while a subclass can only use one abstract class.
• An abstract class can support non-abstract methods while in an interface the methods are all abstract
• An abstract class can declare or use any variables while interface lacks such a capability.
• An abstract class has all its data member or functions private by default while interface have all its members as public and they cannot be changed manually.
• In abstract class abstract keyword is used to declare abstract methods while in interface there is no need to do so.
• Multiple inheritance is not possible in abstract class while the same is possible in interface.
• In abstract-class constructor is utilized while in interface there is not type of constructor that is used.

22. Described namespaces in C#?

• They are containers of the classes and are used for grouping the related classes in C#.

• Typically, the “Using” keyword can be used for using the namespaces in another namespace.

23. Using an example explain how the Keyword “Const” is used in C#

• The keyword is used for making an entity constant.
• It is impossible to reassign a value to constant
• Exampple: const string_name= “Test”;

24. Explain boxing and unboxing

• Boxing is the process of converting a value type data type to the object or to any interface data type which of implemented by this data type. For instance, when the CLR boxes it is simply converting the value type t object type, this done by wrapping a system. Object and stores it in an application domain.

• Unboxing involves extracting the value type from the object or any implemented interface type.

25. Describe the difference between constant and read-only variables in C#?

• Const is used to describe the action of making an entity constant and this cannot modify the value later in the code.

• In read-only variables the values has the flexibility to be changed during runtime and values to read-only can be assigned in constructor or at the time of declaration.

26. Explain value types and references types

• Value types are stored in the stack while references are stored in heap.
• Example of value types includes Int, number, float, and long.
• Examples of references types are String, class, interface and object.

27. Explain the difference between custom control and user control

• Customs controls occur as complied codes and are easier to use. Developers can easily drag and drop the controls into their web forms.

• User controls, on the other hand, are similar to ASP and are easy to create. However, these types of controls cannot be placed in t the toolbox and dragged- dropped from it. They have their own unique design and code. The file extension of user controls is identified as ascx.

28. Describe method overloading?

• This is a situation where a developer creates multiple methods with the same name-bearing unique signatures in the same class.

• During the process the developer uses overload resolution to determine the specific method to be invoked.

29. Explain Dispose ad finalize variables as used in C#

• This approach uses interface and it will free up both managed and unmanaged code such as database connection and files

• Finalize is the method called to internally unlike the Dispose method which is called explicitly. It is always called by garbage collector and cannot be called from the code.

30. State how exceptional handling is carried out in C#?

• In the language there exists a “try… catch” block which is used to handle the error.

31. Is it possible for a private virtual method to be overridden?

• No because they cannot be accessed outside the class

32. Explain the modifier “protected internal”

• These variables r methods are accessible within the same assembly and form the classes that are derived from the parent class.

33. Can developers execute multiple catch block in C#?

It is no possible since once an exception has occurred it executes specific exception catch block and the control comes out.

34. Explain the difference between finalizing and final methods in C#

• Finalize is used for garbage collection. The method is used for cleanup purposes.

• Final is used as method for executing the code regardless if the exception occurred or not.

35. Can developers have only “try” block without “catch” block in C#?

• Developers can work with try block only without catch block but it is necessary to include finally block.

36. State the type of errors in C#?

• Compile time error

• Runtime error

37. Can developers get errors when working with Finally block?

• Yes it is possible to get errors in finally block.

38. In which assembly does System namespace occur in C#?

• It In occurs in mscorlib.dll

39. Can developers use “this” in a static method?

There is no opportunity to use “this” in static method in C#.

40. In try block, if we add return statement whether finally block is executed in C#?

Yes, Finally block will still be executed in presence of return statement in try block.

41. What is an inner exception in C#?

Inner exception is a property of exception class which will give the developer an opportunity to look to the parent and the child exception details.

42. Describe property in C# .Net.

• Properties provide flexibility to read, write or compute values or private fields.
• They can be used to access private fields.
• Property is return type function or method with one parameter of without a parameter.

43. State three types of properties?

• Read/write
• ReadOnly
• WriteOnly

44. What is string builder class in C#?

• It represents a mutable string of characters and the class cannot be inherited.
• It provides an opportunity to insert, Remove, Append and replace the characters.

45. Explain the difference between “StringBuilder” and “String” in C#

• In string builder, once the object has been created it can be modified through Append, Remove or Replace

• With String it is impossible to modify the string object but developers can always create new objects in memory of string type.

46. Explain how the array elements can be sort in descending order in C#

• The method “sort ()” is utilized together with “reverse ()” to sort the array in a descending order.

47. What is a circular reference?

• This is when multiple resources are dependent on each other and there occurs a lock condition and therefore the resources remain unused.

48. State some exceptions in C#?

• NullRferenceException
• ArgumentNullException
• DivideByZeroException
• IndexOutOfRangeException
• InvalidOperationexception
• StackOverFlowExceprion

49. What are extension methods?

• They are used to add methods to existing types without creating new derived type, recompiling or otherwise modifying the original type.

• They are unique in that they closely resemble static method but they are called like the instance methods on the extended type.

50. How is the extension method used?

• In the method the “This” modifier is applied to the first parameter. In this context, the first type of the parameter will be the type that is extended.

51. What does generic mean in C#?

• It is used to make the code reusable and reduce code redundancy and consequently increase the performance and type safety.

• An example of a generic is Namespace – “System.collections.generic”

52. What is an object pool in C#?

• It is utilized in tracking the objects which are used in the code. So the object pool reduces the object creation overhead.

53. What does delegate mean in C#?

• They are type-safe pointers and are used to represent the reference of the methods of some return type and parameters.

54. List types of delegates in C#?

• Single delegate
• Multicast delegate and,
• Generic delegate

55. List three types of delegates found in C#?


56. Differentiate between events and delegates in C#

Events provide one more of encapsulation over delegates.

57. What are the uses of delegates in C#?

• They are used as pointers to functions in C or C++
• A delegate object has the capacity to hold many functions references which is called invocation list that refers to fuctions in a sequence FIFO.

58. What is IEnumerable <> in C#?

It is the parent interface for all non-generic collections in System.collections namespace like ArrayList, HashTable that can be enumerated.

59. State the differences between system.Array.CopyTo () and System.Array.Clone()?

• The clone () method is used to create a new array object which has all elements in the original array and using Copyto() method the developer can copy all the elements into another existing array.

• Both methods are used to achieve a shallow copy.

60. Write down the C# syntax to catch exceptions.

• Try-catch blocks are used to catch an exception.

• Catch block can have a parameter of the system. Exception type.

• Example
Try {
Catch (Exception ex) {

The developer might consider omitting the parameter from the catch statement above.

61. Explain how you can inherit a class into another class in C#

• A colon is the tool used as inheritance operator in C#.
• Inheritance is done by placing colon and then the class name.
• Example: Public class DerivedClass : BaseClass

62. State the base calls in >net from which all the other classes originate from?

• System.Object

63. Describe the difference between methods overriding and overloading?

• In overriding, the developer changes the method defining in the derived class and the action changes the method behavior.

• Method overloading is creating the same name within the same class but having different signatures.

64. Mention the different ways of achieving method overloading?

This can be done by using different data types for a parameter, different order of parameters and different number of parameters.

65. Explain why you can’t specify the accessibility modifier for methods inside the interface

• Typically, interfaces have virtual methods that do not support method definition.

• In the interface all methods are overridden in the derived class and are all public.

66. Can a developer set a class as to be inherited and prevent the method from being overridden?

• Yes it is possible and is done by declaring the class public and setting the method as sealed to prevent it from being overridden.

67. State how nullable types are in .Net are used?

In C# value types occur as either normal value or null value. The values are known as nullable types.

Example: Int? someID = null;
If (someID.HASvAlue)

68. Explain how you can build an array with non-default values

This can be done using Number.Repeat

69. Explain the difference between “Is” and “as” operators in C#

Isis used by developers to check the compatibility mode of an object and it goes the result as Boolean

As is utilized in the casting of an object to a type or a class.

70. Explain what is a multicast delegate

This is a type of delegate that as multiple handlers attached to it.
Each of the handlers is attached to a method.

71. Explain indexers in C# .Net

These are smart arras that can occur in C#. They allow instances of classes to be indexed in the same way as an array.

72. Explain the C# attributes

Attributes are tools used to define declarative tags on some entities such as class and methods.

The information in attributes can be retrieved at Runtime using Reflection.

73. Explain how you would implement singleton design pattern in C#

In this pattern a class can only have one instance and provides an access point to it globally.

74. Explain the difference between Directcast and Ctype in C#

Developers use DirectCast to convert the type of an object that requires the runtime type to be similar to the specified type in Directcast.

Cytepe on the other had is used where the conversion is defined between the expression and the type.

75. State if C# is managed or unmanaged code

Typically, C# is a managed code because common language runtime can compile C# code to an intermediate language.

76. Explain how exception handling is implemented in C#

Try- bears the block of code through which an exertion will be checked.
Catch- this program catches an exception with the help of exception handler.
Finally- this block of codes is prepared to execute regardless of whether an exception is caught or not
Throw- throws an exception in case of a problem

77. Explain what you understand by a deconstructor

This a tool used to clean up memory and free the resources

A garbage collector is used for this purpose and is called by System.GC.Collect()

78. Explain the difference between Continue and break statement

A break statement is utilized to break a loop and this allows the program to exit the loop.

The continue statement do not break a loop but it allows the program to exit the current iteration only.

79. State a syntax for single and multidimensional arrays?

• A single dimensional array have its variables stored in a single low • Example of a single dimensional array; Double numbers = New double [10]
Int [] score = new int[] {25,24,23,25}
• When array occurs in more than one dimension they are called multidimensional arrays.
• Example: Int[,] numbers = new int[3,2] { {1,2} ,{2,3},{3,4}};

80. State some properties of an array?

• Length – gives the total number of element sin an array
• IsfixedSize- highlights if the array is fixed or not
• IsReadOnly- explain if the array is read-only or not.

81. What the properties of a string class?

• Chars- places the Char in the current string
• Length – places the number of objects in current string

82. Explain the escape sequence

Escape sequence is marked by a backlash(\). The item that comes after the backlash should be interpreted literally and treated as a special character

83. Give example of string escape sequence in C#?

\n- newline character
\b- Backspace
\\- backlash
\’ – single quote
\” – double quote

84. Explain regular expression

This a template that matches a set of input. Mostly the pattern includes operators, constructor and character literals.

85. Explain constructor chaining

This a way of connecting two or more classes in a relationship as an inheritance. In this process, every child class is mapped to parent class constructor implicitly by base keyword.

86. Can multiple catch blocks be executed in C#?

Yes we can use multiple catches blocks but only one can be executed

87. Explain the difference between throw exception and throw clause

Throw exception is used to overwrite the stack trace and this means finding the original code line number will not be easy.

Throw clause retains the information and adds to the stack information in the exception that it is thrown.

88. State the difference between Equality operator (==) and Method in C#?

Both methods are used in comparing two value data items or references data items Equality operator (==) is compares the reference identity while the Equals () method compares the contents.

89. Explain the object pool as it is used in .Net

This helps to keep the pool of objects in memory to be re-used and it decreases the load of object created by a great margin.

It is a container of the object that is ready to use.

90. State the uses of delegates in C#?

Callback mechanism
Asynchronous processing
Abstract and encapsulate method

91. Explain why developers use “nullable coalescing operator” (??) in C#

The operator can be used with references types and nullable value types.

If the first operand of the expression is null then the value of the second operand is assigned to the variable.

Example: double? myFirstno = null
Double mySecno;
My Secno = myfristno ?? 10.11;

92. Explain the Hashtable in C#

Used to store the key or value pairs depending on the hash code of the key the key is essential in accessing the element in the collection.

93. State how you would check whether the hash table contains specific key in C#?

“containsKey” is the method I would use for the purpose.

Example of a sample code: myhashtbl.ContainsKey(‘1’)

94. State the loopholes available in C#?

For while
Do.. while

95. Give a sample code to write the contents to text file in C#?

Using System.IO;

File.WriteAllText(”mytextfilePath”, “MyTestContent”);

96. Give the compiler of C#?

The compiler is - CSC.

97. State the different types of unit test cases?

Positive test cases
Negative test cases
Exception test cases

98. List the collection types that work in C#?

• Arraylist
• Stack
• Queue
• SortedList
• Hashtable
• Bit Array

Preparing for the interview

Similar to our other programming interview processes, you can expect to answer some of these questions in person. In that regard, I would prepare yourself by bringing a series of projects or programs which you may have made on your own. If you do not have some examples of software projects you've made, you should spend a weekend putting together something simple. Even the smallest of projects can help employers determine your fit inside the organization and help secure your potential of being hired. It also gives you a great avenue for discussing C# and other ways you implemented a particular piece of functionality utilizing the C# programming language. Think of this as preparing a portfolio or a series of case studies which can easily be digested or shared between colleagues.


As with any of the interview questions pages, I employ you to please email me if you have additional questions that you would like listed or if you see any mistakes that can easily be cleaned up. This resource is vital for those looking to find employment as well as those looking to vet candidates in a professional engineering position.

author: patrick algrim
About the author

Patrick Algrim is an experienced executive who has spent a number of years in Silicon Valley hiring and coaching some of the world’s most valuable technology teams. Patrick has been a source for Human Resources and career related insights for Forbes, Glassdoor, Entrepreneur, Recruiter.com, SparkHire, and many more.


Help us by spreading the word