0% found this document useful (0 votes)
42 views13 pages

Interview QuestionsNC

Interview QuestionsNC

Uploaded by

alimomin661
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views13 pages

Interview QuestionsNC

Interview QuestionsNC

Uploaded by

alimomin661
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Interview Questions .

Net
1. Explain the difference between .NET and C# ?
Ans: C# is a programming language developed by
Microsoft. .NET is a software development framework by
Microsoft. C# is one of the languages used to develop
applications within the .NET framework.
2. .NET Framework(MVC) vs. .NET Core
Ans: .NET Framework is a Windows-only framework for
building Windows applications and Can only be used on
Windows based Machine (Version 4.8).
.NET Core is a cross-platform framework. It is to build to
cross platform Web Applications.We Can use It on any OS like
windows, MacOs , Linux. The Current Version Is 7 and 8 is yet
to come.
3. What is IL (Intermediate Language) Code?
Ans: IL (Intermediate Language) also known as
MSIL(Microsoft Intermediate Language) code is a code
generated by .NET Language specific compilers. It is compiled
to machine code by the JIT compiler at runtime.
4. What is the use of JIT?
JIT (Just-in-Time Compiler) compiler translates IL code into
machine code at runtime, ensuring platform independence
and enabling performance optimizations.
5. Is it possible to view IL code?
 Yes, you can view IL code using tools like ILDASM or by
enabling IL code generation in Visual Studio.
Interview Questions .Net
6: What is the benefit of compiling into IL code?
Ans : Compiling into IL code allows platform independence
and performance optimizations during JIT compilation.
7: Does .NET support multiple programming languages?
Ans : Yes, .NET supports multiple languages like C#, VB.NET,
and F# that compile to a common IL code.
8: What is CLR (Common Language Runtime)?
The Common Language Runtime (CLR) is a component of the
Microsoft .NET Framework. It Converts the IL Code into
Native (Machine Code) .It also Invokes Just-In-Time (JIT)
compiler, which compiles the IL code into machine code on
the fly as the program runs.
Interview Questions .Net
9: What is managed and unmanaged code?
A code which is executed by the CLR is known as Managed
code.
A code which is directly executed by the operating system is
known as Unmanaged code.
10: Explain the importance of Garbage Collector?
GC (Garbage collector) collects all objects that are no longer
used by the application and then makes them free
from memory.
11: Can garbage collector claim unmanaged objects?
No, the Garbage Collector can't manage unmanaged objects
As it is Not Handled by CLR.
12: : Difference between Stack vs. Heap?
ANS : Stack and Heap are 2 Portion on the RAM. Stack is used
to store the Value Types. Heap is used to store the Reference
type Data.
13: What are Value types & Reference types?
Value types store their data directly on the Stack, while
reference types store Memory address on the stack and the
actual data in the heap.
16: Explain boxing and unboxing?
Boxing converts a value type to an Object type, while
unboxing extracts the value type from object.
Interview Questions .Net
17: Explain casting, implicit casting, and explicit casting?
Casting is the conversion of one data type to another. In
Implicit casting a smaller Data Type is Converted in to a bigger
data type eg:- int is converted in bool type
In Explicit Casting a bigger Data Type is Converted in to a
smaller data type eg:- bool is converted in int type
18: What can happen during explicit casting?
During explicit casting, data loss can occur.
19: Differentiate between Array and ArrayList?
Arrays have a fixed lenght, store elements of the same type,
and are more efficient. ArrayList has flexible lenght and it is
not type safe.
ArrayList Syntax -
NameSpace - System.Collections;
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
Array Syntax –
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
Console.WriteLine(cars[0]);
// Outputs Volvo
Interview Questions .Net
22: What are generic collections?
Generic collections in .NET allow you to create type-safe
collections. Generic List are Type Safe and also have flexible
length.
23: How do we handle exceptions in C# (try/catch)?
In C#, you use a try-catch block to handle exceptions. Code
that may throw an exception is placed within the try block,
and the exception-handling logic is placed within the catch
block.
24: What is the need for "finally"?
The finally block is used to ensure that a piece of code
executes regardless of whether an exception is thrown or not.
25:What is Delegates?
A delegate is an object which refers to a method or you can
say it is a reference type variable that can hold a reference to
the methods.
[modifier] delegate [return_type] [delegate_name]
([parameter_list]);
You can create a delegate by defining a delegate type and
assigning a method to it.
Syntax example:
public delegate int MathOperation(int a, int b);
MathOperation add = (a, b) => a + b;
Interview Questions .Net
26:Why do we need OOP?
Object-Oriented Programming (OOP) provides a way to model
real-world entities, organize code, and promote code
reusability. It enhances modularity, maintainability, and
extensibility of software.
27: What are the important pillars of OOP?
The four important pillars of Object-Oriented Programming
(OOP) are:
1-Encapsulation: Bundling data and methods into a single
unit (class).
2-Abstraction: Hiding complex details and showing only the
necessary features.(Method)
3-Inheritance: Inheriting a class with another class to access
properties and Methods with : Symbol.
Types of Inheritance in C#:- Single level – Class B : Class A
Multi-Level - – Class B : Class A , Class C : Class B
Hierarchical inheritance - Class B : Class A , Class C : Class A,
Class D : Class A
4-Polymorphism: The polymorphism means taking shapes.
Example-Method and Constructor Overloading. Same name
but different parameters
There are two types of polymorphism in C#:
1)Static / Compile Time Polymorphism – Method Overloading
2) Dynamic / Runtime Polymorphism – Method Overriding
Interview Questions .Net
28: Explain the "virtual" keyword?
In C#, the "virtual" keyword is used to declare a method in a
base class that can be overridden in derived classes.
29: Overloading vs Overriding?
Overloading involves multiple methods with the same name
but different parameters within the same class. Overriding
involves providing a new implementation for a method in a
derived class that is originally declared as virtual or abstract
in the base class.
30: Why do we need Abstract classes?
An abstract class in C# is a class that cannot be instantiated
and is made to be used as a base class for other classes. An
abstract class can contain abstract methods, which are
methods without an implementation, and must be
overridden in a derived class. An abstract class can also
contain non-abstract methods, which have an
implementation, and can be overridden in a derived class if
needed. These methods can be used as common
functionality for all derived classes. In summary, the purpose
of an abstract class in C# is to provide a common interface
and implementation for derived classes.
31: Can we create an instance of Abstract classes?
No, you cannot create an instance (Object) of an abstract
class.
 Can we create a Constructor of Abstract classes?
YES It will bring the properties of Abstract class in Living State
Interview Questions .Net
Difference between Abstract Class and Interface in C#

Abstract Class Interface

An abstract class can consist of An interface can have only abstract


abstract and non-abstract methods. methods.

Abstract classes do not support An interface allows multiple


multiple inheritance. inheritance.

Abstract classes can have static Interfaces can not have static members
members. .

They can have methods, constants, They can have only indexers, methods,
fields, etc. events, and properties.

You need to use You need to use the interface keyword


the abstract keyword to declare an to declare an interface.
abstract class.

Abstract classes have a constructor. Interfaces don’t have a constructor.

They are faster than interfaces in They are slower than abstract classes
terms of performance. in terms of performance.

It consists of both declaration and It only consists of a declaration without


definition. definition.

32 : Method Shadowing
Interview Questions .Net
Method shadowing in C# is a way to create a new method in
a derived class that has the same name as a method in the
base class, without intending to override the base class
method. The new method "shadows" or hides the base class
method. When you call the method on an instance of the
derived class, the new method in the derived class is
executed, not the one in the base class. It's like having two
methods with the same name, but they are separate and
don't have any connection to each other.
33: Shadowing vs Overriding?
Shadowing and overriding are different mechanisms.
Overriding is used to provide a new implementation for a
method in a derived class, while shadowing is used to create
a new method that has the same name as a base class
method but does not override it.
34 :When do we need Shadowing?
Shadowing allows you to override the behavior of a parent
class member in the derived class. This can be
important . when you want to change the behavior of a base
class member to match the requirements of the derived
class.
35:Explain Sealed Classes?
Sealed classes are used to restrict the users from inheriting
the class. A class can be sealed by using the sealed keyword.
The keyword tells the compiler that the class is sealed, and
therefore, cannot be extended. No class can be derived from
a sealed class.
Interview Questions .Net
36:What are nested classes?
A nested class in C# is like a class inside another class. It's a
way to group related classes together. Think of it as putting a
smaller box inside a bigger box.The special thing about nested
classes is that they can see and use the stuff (variables,
methods) in the outer (or containing) class. So, it's like the
smaller box can access things in the bigger box.They can also
access private members of the outer class.
Can nested classes access outer class variables?
Yes, nested classes can access private members (variables,
methods) of the outer class. This is known as an inner class's
ability to capture the outer class's context.
Can we have public and protected access modifiers in
nested classes?
Yes, you can use public and protected access modifiers for
nested classes.
37:What is SOLID?-The goal of SOLID principles is to create
software that is easier to maintain, extend, and adapt to
changing requirements while reducing the risk of introducing
bugs during modification.
 S: Single Responsibility Principle (SRP)
 O: Open-closed Principle (OCP)
 L: Liskov substitution Principle (LSP)
 I: Interface Segregation Principle (ISP)
 D: Dependency Inversion Principle (DIP)
Interview Questions .Net

1. Single Responsibility Principle (SRP): A class should


have just one job or responsibility. It's like a good worker
who does one task well without getting distracted by
other things.
2. Open/Closed Principle (OCP): Code should be open for
extension but closed for modification. Imagine you have
a toy. You can add new parts to make it better, but you
don't have to break it to make changes.
3. Liskov Substitution Principle (LSP): Subclasses should be
able to replace their base class without causing
problems. Think of it like replacing your regular bicycle
wheel with a more advanced one without changing the
entire bike.
4. Interface Segregation Principle (ISP): Don't make classes
implement interfaces they don't need. It's like having a
menu with only the items you want to eat instead of a
long list of everything.
5. Dependency Inversion Principle (DIP): High-level
modules should not depend on low-level modules. Both
should depend on abstractions (interfaces). It's like a
remote control that works with many different TV
brands without being hardcoded to one.
Interview Questions .Net
What is Dependency Injection ?
D.I is a technique to make our project Decoupled and Module
Independent In simple words the Objects which are meant to
be used in whole project are Initialize at a place and then
used in whole project. We don’t have to use ‘new’ keyword
again and again to make a object everywhere.
In .NET Core DI has built-in support but in MVC (4.8) we have
to install a package named ‘Autofac’ to use the functionality
of Dependency injection .We have to register our Controller
in Application_Start and then we have to register our type
and write the Class name of whose Object we need. Using
the SingleInstence(); Method will prevent the duplicating of
objects.
Note – Use Documentation of AutoFac MVC for Codes
Interview Questions .Net

You might also like