1. What is Reflection in C#?

Reflection is a feature in C# that allows a program to inspect metadata of assemblies, classes, methods, properties, and attributes at runtime.

2. Why is Reflection used?

Reflection is used for dynamically loading assemblies, inspecting types, invoking methods dynamically, and building frameworks such as dependency injection containers.

3. What is the Assembly class?

The Assembly class represents a compiled code library (.dll or .exe) and allows you to load assemblies and access their metadata.

4. What is the Type class?

The Type class represents type declarations such as classes, interfaces, arrays, and structures.

5. How do you get type information using Reflection?

Type t = typeof(Student);

6. What is Activator class?

Activator class creates instances of objects dynamically at runtime.

7. Example of creating object using Reflection

var obj = Activator.CreateInstance(typeof(Student));

8. What are Attributes?

Attributes are metadata used to add information to classes, methods, and properties.

9. What is GetMethods()?

This method retrieves all methods of a class using Reflection.

10. What is GetProperties()?

It returns the list of properties defined in a class.

11. What is late binding?

Late binding means resolving method calls at runtime instead of compile time.

12. What is early binding?

Early binding means method calls are resolved during compilation.

13. What is MethodInfo?

MethodInfo represents information about a method including name, parameters, and return type.

14. What is PropertyInfo?

PropertyInfo represents metadata information about properties.

15. What is FieldInfo?

FieldInfo provides information about fields of a class.

16. What is ConstructorInfo?

ConstructorInfo represents metadata about constructors.

17. Can Reflection access private members?

Yes, Reflection can access private members using BindingFlags.

18. What is BindingFlags?

BindingFlags are used to control how Reflection searches for members.

19. What are disadvantages of Reflection?

  • Performance overhead
  • Complex debugging
  • Security risks

20. Where is Reflection commonly used?

Reflection is used in frameworks like Entity Framework, dependency injection frameworks, and unit testing tools.

21. What are Generics?

Generics allow creating classes, methods, and collections that work with any data type while maintaining type safety.

22. Example of Generic Class

class Sample<T>
{
public T data;
}

23. Why use Generics?

  • Code reuse
  • Type safety
  • Better performance

24. What is Generic Method?

A method that works with different data types using type parameters.

25. Example of Generic Method

public void Display<T>(T value)
{
Console.WriteLine(value);
}

26. What are Generic Collections?

Collections that use generics like List<T>, Dictionary<TKey,TValue>.

27. Difference between ArrayList and List<T>?

ArrayList stores objects and requires casting, while List<T> is strongly typed.

28. What is Generic Constraint?

Constraints restrict the types that can be used with generics.

29. Example of Generic Constraint

class Test<T> where T : class

30. What is new() constraint?

Ensures the type parameter has a parameterless constructor.

31. What is struct constraint?

Ensures the type parameter is a value type.

32. What is class constraint?

Ensures the type parameter is a reference type.

33. Can generics be used with interfaces?

Yes, interfaces can be generic.

34. Example of Generic Interface

interface IRepository<T>
{
void Add(T item);
}

35. What are benefits of Generics?

  • Type safety
  • Code reusability
  • Performance improvement

36. Can Generics improve performance?

Yes, because boxing and unboxing are avoided.

37. What is boxing?

Converting value type into object type.

38. What is unboxing?

Converting object type back into value type.

39. Can delegates be generic?

Yes, delegates can also use generics.

40. Example of Generic Delegate

Func<int,int> square = x => x * x;

41. What is Dependency Injection?

Dependency Injection is a design pattern used to achieve loose coupling between classes.

42. Why use Dependency Injection?

  • Loose coupling
  • Better testability
  • Maintainable code

43. What is Inversion of Control (IoC)?

IoC means control of object creation is transferred to a container.

44. Types of Dependency Injection

  • Constructor Injection
  • Property Injection
  • Method Injection

45. What is Constructor Injection?

Dependencies are passed through the constructor.

46. Example of Constructor Injection

public class Service
{
private IRepository repo;
public Service(IRepository repository)
{
repo = repository;
}
}

47. What is Property Injection?

Dependencies are provided through properties.

48. What is Method Injection?

Dependencies are passed through methods.

49. What is DI Container?

A DI container manages object creation and dependency resolution.

50. Examples of DI Containers

  • Unity
  • Autofac
  • Ninject

51. What is Service Lifetime?

Defines how long a service instance exists.

52. Types of Service Lifetime

  • Singleton
  • Scoped
  • Transient

53. What is Singleton?

Only one instance is created for the entire application.

54. What is Scoped?

One instance per request.

55. What is Transient?

A new instance is created every time.

56. What is service registration?

Adding services to the DI container.

57. Example

services.AddScoped<IRepository, Repository>();

58. What is loose coupling?

Classes depend on interfaces rather than concrete implementations.

59. What is tight coupling?

Classes directly depend on concrete classes.

60. Advantages of DI

  • Easy testing
  • Better maintainability
  • Flexible architecture

61. What is MVC?

MVC stands for Model View Controller design pattern.

62. Components of MVC

  • Model
  • View
  • Controller

63. What is Model?

Model represents business logic and data.

64. What is View?

View displays the UI.

65. What is Controller?

Controller handles user requests.

66. What is Razor View Engine?

Razor is a markup syntax used to create dynamic web pages.

67. What is Action Method?

A method inside a controller that responds to user requests.

68. What is Routing?

Routing maps URLs to controller actions.

69. What is ViewBag?

ViewBag is a dynamic object used to pass data from controller to view.

70. What is TempData?

TempData stores data temporarily for one request.

71. What is strongly typed view?

A view that binds directly to a model class.

72. What are partial views?

Reusable UI components.

73. What is Layout page?

A common template used across multiple views.

74. What is Html Helper?

Methods used to generate HTML elements.

75. Example Html Helper

@Html.TextBox("Name")

76. What is Model Binding?

Automatically mapping request data to action method parameters.

77. What are filters?

Filters execute logic before or after action methods.

78. Types of Filters

  • Authorization
  • Action
  • Result
  • Exception

79. What is RESTful routing?

Using HTTP verbs like GET, POST, PUT, DELETE.

80. Advantages of MVC

  • Separation of concerns
  • Testability
  • Better control over HTML

Entity Framework (Questions 81 – 100)

81. What is Entity Framework?

Entity Framework is an ORM (Object Relational Mapper) used to interact with databases.

82. What is ORM?

ORM maps database tables to C# classes.

83. What is DbContext?

DbContext represents a session with the database.

84. What is DbSet?

DbSet represents a collection of entities.

85. What is Code First?

Database is created from C# classes.

86. What is Database First?

Model is created from existing database.

87. What is Model First?

Database and model are created from design.

88. What are migrations?

Migrations update database schema.

89. Command to add migration

Add-Migration InitialCreate

90. Command to update database

Update-Database

91. What is Lazy Loading?

Related data is loaded automatically when accessed.

92. What is Eager Loading?

Related data is loaded immediately using Include.

93. Example

context.Students.Include(s => s.Courses);

94. What is LINQ?

LINQ is used to query data using C# syntax.

95. Example LINQ Query

var students = context.Students.Where(s => s.Age > 18);

96. What is change tracking?

EF tracks entity changes automatically.

97. What is SaveChanges()?

Persists changes to the database.

98. Advantages of Entity Framework

  • Less code
  • Rapid development
  • Strong integration with .NET

99. Disadvantages

  • Performance overhead
  • Complex queries can be slow

100. When should EF be used?

Entity Framework is best used for enterprise applications where rapid development and maintainability are important.

📢 Join Our WhatsApp Channel

💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.

👉 Join WhatsApp Now

📢 Join Our Telegram Channel

💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!

👉 Join Telegram

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 - 2025 itfreesource.com

Enable Notifications OK No thanks