Top Basic .NET Interview Questions and Answers for Freshers – Easy to Reply

Below are 25 basic .NET interview questions and answers for freshers, designed to be easy to understand and cover fundamental concepts:


1. What is .NET?

Answer:
.NET is a free, cross-platform, open-source framework developed by Microsoft for building various types of applications, including web, desktop, mobile, cloud, and gaming applications. It supports multiple programming languages like C#, F#, and VB.NET.


2. What is the difference between .NET Framework, .NET Core, and .NET 5/6/7?

Answer:

  • .NET Framework: The original .NET platform for building Windows applications (not cross-platform).
  • .NET Core: A cross-platform, high-performance framework for building modern applications.
  • .NET 5/6/7: The unified platform that combines .NET Core, .NET Framework, and Xamarin into a single platform.

3. What is C#?

Answer:
C# (pronounced “C-sharp”) is a modern, object-oriented programming language developed by Microsoft. It is widely used for building .NET applications.


4. What is the Common Language Runtime (CLR)?

Answer:
The CLR is the execution engine of .NET that manages memory, handles exceptions, and provides services like garbage collection, type safety, and security.


5. What is the Common Type System (CTS)?

Answer:
The CTS defines how types are declared, used, and managed in .NET. It ensures that objects written in different .NET languages can interact with each other.


6. What is the Base Class Library (BCL)?

Answer:
The BCL is a collection of reusable classes, interfaces, and value types that provide core functionality for .NET applications, such as file I/O, collections, and threading.


7. What is the difference between value types and reference types?

Answer:

  • Value Types: Store data directly in memory (e.g., int, char, struct). They are stored on the stack.
  • Reference Types: Store a reference (memory address) to the data (e.g., class, string, array). They are stored on the heap.

8. What is boxing and unboxing?

Answer:

  • Boxing: Converting a value type to a reference type.
  • Unboxing: Converting a reference type back to a value type.

Example:

int x = 10;
object obj = x; // Boxing
int y = (int)obj; // Unboxing

9. What is the difference between == and .Equals() in C#?

Answer:

  • ==: Compares references for reference types and values for value types.
  • .Equals(): Compares the content or values of objects.

Example:

string s1 = "hello";
string s2 = "hello";
Console.WriteLine(s1 == s2); // True (same content)
Console.WriteLine(s1.Equals(s2)); // True (same content)

10. What is the difference between String and StringBuilder?

Answer:

  • String: Immutable (cannot be changed after creation).
  • StringBuilder: Mutable and efficient for string manipulation (e.g., appending, replacing).

11. What is the difference between abstract class and interface?

Answer:

  • Abstract Class: Can have both abstract (no implementation) and concrete (with implementation) methods. It supports constructors and fields.
  • Interface: Can only have method signatures (before C# 8). From C# 8, interfaces can have default implementations. It does not support constructors or fields.

12. What is the using statement in C#?

Answer:
The using statement is used to ensure that resources (e.g., file handles, database connections) are disposed of automatically when they are no longer needed.

Example:

using (var file = new StreamReader("file.txt")) {
    string content = file.ReadToEnd();
} // File is automatically closed here

13. What is garbage collection in .NET?

Answer:
Garbage collection is an automatic memory management feature in .NET that reclaims unused memory by deallocating objects that are no longer in use.


14. What is the difference between const and readonly?

Answer:

  • const: A compile-time constant that cannot be changed.
  • readonly: A runtime constant that can be initialized only once (e.g., in the constructor).

15. What is the difference between ref and out parameters?

Answer:

  • ref: Requires the variable to be initialized before passing it to the method.
  • out: Does not require initialization before passing it to the method.

Example:

void Modify(ref int x, out int y) {
    x = 10;
    y = 20;
}

int a = 5, b;
Modify(ref a, out b);
Console.WriteLine(a); // 10
Console.WriteLine(b); // 20

16. What is the difference between throw and throw ex?

Answer:

  • throw: Preserves the original stack trace.
  • throw ex: Resets the stack trace, making debugging harder.

17. What is a delegate in C#?

Answer:
A delegate is a type-safe function pointer that holds a reference to a method with a specific signature.

Example:

delegate void MyDelegate(string message);
MyDelegate del = Console.WriteLine;
del("Hello, World!");

18. What is an event in C#?

Answer:
An event is a special type of delegate used to notify other classes when something happens.

Example:

class Button {
    public event EventHandler Click;
    public void OnClick() {
        Click?.Invoke(this, EventArgs.Empty);
    }
}

19. What is the difference between IEnumerable and IQueryable?

Answer:

  • IEnumerable: Used for in-memory collections (e.g., lists, arrays). Executes queries on the client side.
  • IQueryable: Used for querying data from databases. Executes queries on the server side.

20. What is LINQ?

Answer:
LINQ (Language Integrated Query) is a feature in C# that allows querying data from collections, databases, and XML using a SQL-like syntax.

Example:

var result = from num in numbers
             where num > 5
             select num;

21. What is ASP.NET?

Answer:
ASP.NET is a framework for building web applications and services. It includes ASP.NET MVC, ASP.NET Web API, and ASP.NET Core.


22. What is the difference between ViewData, ViewBag, and TempData in ASP.NET MVC?

Answer:

  • ViewData: A dictionary for passing data from the controller to the view.
  • ViewBag: A dynamic wrapper around ViewData.
  • TempData: Used to pass data between actions (persists for one additional request).

23. What is Entity Framework?

Answer:
Entity Framework (EF) is an ORM (Object-Relational Mapping) framework that simplifies database interactions by allowing developers to work with databases using .NET objects.


24. What is the difference between async and await?

Answer:

  • async: Marks a method as asynchronous.
  • await: Pauses the execution of an async method until the awaited task completes.

Example:

async Task<string> GetDataAsync() {
    return await SomeLongRunningOperation();
}

25. What is dependency injection in .NET?

Answer:
Dependency Injection (DI) is a design pattern used to achieve Inversion of Control (IoC). It allows objects to receive dependencies from an external source rather than creating them internally.

Example:

public class MyService {
    private readonly ILogger _logger;
    public MyService(ILogger logger) {
        _logger = logger; // Dependency injected
    }
}

These questions and answers cover the fundamental concepts of .NET and C# and are commonly asked in interviews for freshers. Make sure to practice coding examples to reinforce your understanding!

*************** ALL THE BEST *****************
Visit JaganInfo youtube channel for more valuable content https://www.youtube.com/@jaganinfo

Similar Posts you may get more info >>