C# Interview Questions
Best C# Interview Questions And Answers
C sharp is a component-oriented, general-purpose computer programming language that encompasses strong typing, declarative, imperative, and object-oriented disciplines. It is a multi-paradigm language that was initially designed for Common Language Infrastructure (CLI)
Why It is used for?
You can write desktop applications, Console applications, ASP.NET applications, and scalable cloud apps. These are only a few of the uses of C#; a skilled developer can do a lot more than this.
|1.||Programming language||Framework on which the language is built|
|2.||Runs on the .NET framework||Primarily runs on Windows|
|3.||One of the many languages in the .NET Framework||Includes various languages under it|
The term "sharp" is inspired by music notation that indicates that the musical note should be higher in pitch. This has been applied to the language C++, where "++" indicates that its performance will ideally be improved or increased by 1. The sharp symbol resembles four "+" symbols (in a grid of two-by-two), that may imply to some that C# is an advanced or improved version of C++. We have the most extensive question bank to help you answer C# interview questions.
In C#, the different types of classes are Partial class, Sealed class, Abstract class, and Static class.
|S.no||Dynamic type variables||Object type variables|
|1.||Introduced in C# 4.0||Introduced in C# 1.0|
|2.||Handle-type checking at runtime||Handle type checking at compile time|
|3.||Casting not required||Cast object variables to original types|
|S.no||Constant variables||Read-only variables|
|1.||Declared at compile time||Used to assign a value at run time|
|2.||Value cannot be changed||Value can be changed|
|1.||Called after execution of block||Called before garbage collection|
|2.||Used for exception handling.||Used for performing clean up operations|
|3.||Usually contains clean-up code||Automatically called when an instance is not called subsequently.|
|1.||An access modifier||A type modifier|
|2.||Declared variables are accessible from anywhere||Declared variables are globally accessible||Variable does not return value|
Value types in C# are stored in a Stack. For example, int, byte, double.
Reference types in C# are stored on a heap. For example, string, interface.
A constructor in C# is a member function of a class that contains the same name as its parent class. This function gets automatically invoked when an object class gets created. A constructor constructs values in data members while initializing the parent class.
There are five types of constructors - Static constructor, Private constructor, Copy constructor, Default constructor, and Parameterized constructor.
|2.||Inheritance not supported||Inheritance supported|
|3.||Members public by default||Members private by default|
StreamReader and StreamWriter are two different classes in namespace System.IO. Both of these classes are used when the user wants to read or write charact90 and Reader-based data, respectively.
Members of StreamReader inlcude, Close(), Read(), Readline().
Members of StreamWriter include, Close(), Write(), Writeline().
This is an essential topic in C# interview questions for experienced professionals. Some of the basic string operations in C# are Concatenate, Modify, Compare and Search.
A Delegate in C# is a variable, which holds a reference to a specific method. This also makes a delegate a function pointer of a reference type. All the Delegates are derived from the System. Delegate namespace.
Delegates are of three types -
- Single Delegate
- Multicast Delegate
- Generic Delegate
Synchronous is one of the ways to create a thread-safe code in C# where only one thread is able to access resources at any time.
Asynchronous call waits for a method to get completed before continuing with program flow. In an Asynchronous operation, the method call immediately returns so that the program can perform operations while the called method finished its task.
|1.||Used for creating a new array containing elements of the original array||Elements of existing array get copied into another existing array.|
|2.||Does not require a destination array to exist||Destination array must exist|
- Used to check compatibility of the object with a given type
- Returns result as Boolean.
- Used for the casting of the object to type or class
Hiring managers will be impressed if you have this information during C# interview questions. A Thread in C# is a set of guidelines or instructions that are executed, and enable the program to do concurrent processing. The concurrent processing of a program helps the developers handle more than one operation at a given time.
The different states of thread are listed below-
In C#, Stack is used during the static memory allocation. The variables that are allocated on the stack are stored directly in memory and access to this memory is fast. Heap is used during the dynamic memory allocation. The variables that are allocated on heap have memory allocated during runtime and access to this memory is slow.
Note: If you are preparing for a C# interview, you can read our C# technical interview questions for in-depth knowledge.