In this series of Interview questions, I tried to cover a very minor questions which sometimes gives out of syllabus feeling during interview. This is the first part of the series. Hope you find it very helpful.
What is C#?
C# is an object-oriented language that is invented by Microsoft in 2000. It is a part of .net framework. It is used to build many types of applications such as websites, mobile applications, desktop applications and cross platform form applications. Initially it was not open source but now Microsoft made it open source. It’s very first version was launched in 2002.
What is open source?
Open-source term is used to describe a software/component whose code is publicly available and anyone can modify it and use it for their own purpose. It also boosts the flexibility of the software as anyone can contribute towards the betterment of the software.
What is .Net framework?
.NET framework is the collection of Microsoft technologies under one package which is used to create robust and scalable various types of applications. Net stands for Network Enabled Technology. >net supports 60+ languages, 9 are designed by Microsoft and rest are non-Microsoft. It initially focused on windows only but now days (updated version .NET core) it focusses on cross platform operating systems. It consists of 2 components
Class libraries (CL)
Common Language Runtime (CLR)
What are the Class Libraries?
Class Libraries are the pre-built written code libraries by Microsoft for user convenience. User can import those libraries and can-do specific action. It is basically collection of various data types and namespaces.
What is CLR?
The CLR is the heart of .net environment that helps the execution of user written code. It converts the MSIL (Microsoft Intermediate language) to the native code and provides the runtime environment to execute the code. It also provides services like thread management, type safety and exception handling.

What is MSIL/IL?
The MSIL/IL is half compiled code which is CPU independent and can’t be run on any OS. CLR takes it and gives to JIT (Just In Time) compiler and converts it into machine language according to the environment.
What are the main parts of CLR?
There are following parts of CLR
Security Manager
JIT Compiler
Memory Manager
Garbage Collector (GC)
Exception Manager
Common Language Specifications (CLS)
Common Type System (CTS)
What is Garbage Collector?
Garbage Collector is automatic memory collection facility provided by CLR. The GC handles the memory allocation and memory release by itself. The GC uses heap memory for memory calculations. Developer can also call the GC by calling GC.Collect() method where needed, but this is not recommended for production as it can cause some unexpected behavior of the application.
What are Common Language Specifications?
CLS is the set of syntactical rules and restrictions which are used to write code for different languages. Every single code language has its own rules to write code and during compilation, compiler use these rules to convert the code into MSIL. The CLS also helps is cross language integration in case of multiple languages are involved in a project.
What is Common Type System?
CTS is related to the data types of different languages. During the time of compilation, a language’s data types are converted into CLR’s own data types which are known as CTS. CTS provides common data types in case of multiple languages which is very beneficial for compiler to understand the code and execute in effective manner.
What is object-oriented language in simple practical manner?
Object can be anything such as a person or any feature of a particular thing. Let’s take an example of an Appointment Scheduling software of a hospital. In this software there will be multiple sections that will be work as an object such as an applicant, a doctor, an application of the applicant and many more. These objects will communicate with each other and make a productive decision as a result.
What is IDE?
IDE is Integrated Development Environment a software used to write and debug code and run applications. There are many IDE available such as Visual Studio for C# and many other languages, Android Studio for Android development etc.
What is Managed and Unmanaged code?
The code written under .net framework is known as Managed code and the code which is not written under .net framework language is known as Unmanaged code. The Unmanaged code can’t be run under CLR and executed by any OS directly.
Is C# a case sensitive language?
Yes, C# is a case sensitive language. The class defined with MyClass name will not accept as myclass name. Compiler will treat it as different class.
What is difference between WriteLine() and Write() methods?
Both methods are used to write some message in respective application. WriteLine method add a newline character after the end of message while Write method keeps the control in same line.


What are various types of comments in C#?
Single Line: Single line comment used to comment code for a single line and denoted with double slashes (//) used just before the starting of code. It also can be used for multi lines.
Multiline Comments: Multiline Comments are used to comment code for multi lines. It starts with /* and end with */

What is a variable?
A variable is a container to store value. There are following type of variables available in C#.
Int, long: whole numbers (123, -123)
double, float: decimals (0.22)
char: single character (‘a’)
string: full text (“This is string”)
bool: true or false
DateTime: date time of different time zones
What is a literal?
Literal is the fixed (or hard coded) value given to a variable and this value can’t be modified during the execution of the program.
int x = 100;
here x is variable name and 100 is a literal.
What is a Constant?
Constant means unchangeable and read-only. Constant is a keyword used to assign pre-defined value such as pi. The constant is only used when we already know the value.
const double pi = 3.14;
A value must be assigned to a constant variable otherwise it will throw error as its evaluation is done at compile time.

It can be declared inside the method.
Its value can’t be changed.
It can’t be used with static keyword.
What is ReadOnly?
A ReadOnly variable is used to set read only value at compile time. Its value can be changed after declaration.
As its evaluation is done at runtime its value can be assigned while declaring and in constructor.
It can be used with static keyword.
It is commonly used to read config files and database connections.
How we can define multiple variables?
There are 2 ways to define multiple variables:
Using single variable declaration
int a = 0;
int b = 1;
Using multiple variable declaration
int a = 0, b=1;
What is var keyword and why it is used?
Var keyword introduced in C# 3.0 used to declare variable without declaring any explicit data type i.e. especially when we don’t know what would be the data type of that variable. The type of the variable is recognized at compile time.
var x = 90;
The var keyword variable must be initialized in same statement as it has early binding type behavior.
var x; //error var must be initialized
var x = 0; //correct way
The var keyword variable can’t be initialized with null.
var x = null; // error
Multiple variables can’t be declared using var keyword.
var x = 0, y = 1, z = 2; //error
Var keyword variable is only allowed to declare inside a method not at class level.
It performs better in most of cases as it does not require boxing and unboxing.
What is dynamic keyword and how it is different from var keyword?
Dynamic keyword was introduced in C# 4.0. It is also giving a free hand to developer to define variable without any explicit data type. Since the type is assigned by compiler at runtime developer can initialized it without any value. The initial IntelliSense help (VS show its methods) is not available for dynamic variable but available for var keyword variable.
dynamic x; // no error
dynamic x = 0; // no error
What operators are used in C#?
Operators are used to define some specific action between variables and iterations. There are following types of operators available in C#:
Arithmetic operator : Addition (+), Subtraction (-), Multiply (*), Divide (/), Modulus (%)
Assignment operator: Assignment (=), +=, -=, *=, /=
Comparison operator: Equal to (==), Not equal to (!=), Greater than (>), Less than (<)
Logical operator : AND (&&), OR (||), and NOT (!)
Unary operator : ++, --
Ternary operator : ? !
What is Type casting?
Type Casting is the process of converting one data type to another. There are 2 types of Type casting as follows:
Implicit (Automatically)
int i = 9;
double j = i;
//output
Console.WriteLine(i); // 9
Console.WriteLine(j); // 9
Explicit (Manually)
double i = 9.44;
int j = (int)i;
//output
Console.WriteLine(i); // 9.44
Console.WriteLine(j); // 9
What is an Enum?
Enum are Enumerations. Enums are strongly type name constant which are used to assign a value to each member of enum. The default type of an enum is int. Enums are sealed and can’t be inherit. Classes are not allowed to inherit enum. Enums are very useful for comparison purpose. For example, in a project developer can declare a Status enum and use it anywhere where status is involved. One major benefit of enum is that it is easy to handle as its value can be changed at one place, you do not need to change the value where status is used in the project.
public enum Status
{
Active,
Inactive
}
To consume enum it can be access directly like Status.Active. It also can be convert into int i.e. Convert.ToInt(Status.Active), it will return 0 as value. The 0 value is assigned by default. Developer can assign any value like
public enum Status
{
Active = 100,
Inactive = 200
}
What are Escape Characters?
Escape characters are used to represent some special character in the sentence. They are start with back slash (\).


Join the conversation! Your thoughts help the community grow.