This document contains a summary of 50 common .NET interview questions and their answers. Some key topics covered include:
- The differences between .NET Framework and .NET Core.
- Components of the .NET Framework like CLR, CTS, JIT.
- ASP.NET, MVC, Web API frameworks.
- Concepts like value types vs reference types, boxing/unboxing, delegates, LINQ, Entity Framework.
- Exception handling, attributes, reflection, polymorphism.
The questions cover fundamental .NET concepts, common .NET classes and frameworks, OOP principles in .NET and C#, and memory management/performance topics. The answers concisely explain each concept in
This document contains a summary of 50 common .NET interview questions and their answers. Some key topics covered include:
- The differences between .NET Framework and .NET Core.
- Components of the .NET Framework like CLR, CTS, JIT.
- ASP.NET, MVC, Web API frameworks.
- Concepts like value types vs reference types, boxing/unboxing, delegates, LINQ, Entity Framework.
- Exception handling, attributes, reflection, polymorphism.
The questions cover fundamental .NET concepts, common .NET classes and frameworks, OOP principles in .NET and C#, and memory management/performance topics. The answers concisely explain each concept in
NET Framework is a software development platform developed by Microsoft. It provides a runtime and a set of libraries that allow developers to build and run applications for Windows, web, mobile, and more. 2. What is the difference between .NET Core and .NET Framework? .NET Framework is the original platform for building Windows desktop applications and ASP.NET web applications. .NET Core is a cross-platform, open-source framework that can be used to build modern, cloud-based web applications, microservices, and more. 3. What is CLR? CLR stands for Common Language Runtime. It is the heart of the .NET Framework and provides the execution environment for all .NET code. It handles memory management, garbage collection, and more. 4. What is CTS? – CTS stands for Common Type System. It ensures that data types defined in two different languages get compiled to a common data type, ensuring interoperability between languages. 5. What is JIT? JIT stands for Just-In-Time compiler. It converts Intermediate Language (IL) code into machine code just before the application runs. 6. What is ASP.NET? ASP.NET is a web application framework developed by Microsoft that allows developers to build dynamic web applications, web services, and web pages using .NET languages. 7. What is the difference between Response.Redirect and Server.Transfer? Response.Redirect redirects the user to another page or site and performs a trip to the client. Server.Transfer transfers the user to another page on the same server without making a round trip to the client. 8. What is the difference between a value type and a reference type? Value types store the actual data, while reference types store a reference to the data's memory location. Value types are stored on the stack, while reference types are stored on the heap.
9. What is Garbage Collection in .NET?
Garbage Collection (GC) is a process by which the .NET runtime automatically reclaims memory that is no longer in use by the application. It frees up memory that is occupied by objects that are no longer referenced. 10. What is the difference between Finalize and Dispose methods? The Finalize method is used to free unmanaged resources before an object is garbage collected, while the Dispose method is used to free both managed and unmanaged resources manually. 11. What is Boxing and Unboxing in .NET? Boxing is the process of converting a value type to a reference type (object). Unboxing is the reverse process, converting a reference type back to a value type. 12. What is a Delegate? A delegate is a type-safe function pointer that can reference a method with a specific signature. It allows methods to be passed as parameters. 13. What are Lambda Expressions? Lambda expressions are a concise way to represent anonymous methods (methods without a name). They can be used primarily to define inline methods. 14. What is LINQ? LINQ stands for Language Integrated Query. It provides a consistent model for querying data across various kinds of data sources and formats. 15. What is Entity Framework? Entity Framework (EF) is an ORM (Object-Relational Mapping) framework that allows developers to work with relational databases using .NET objects. It eliminates the need for most of the data-access code developers usually need to write. 16. What is the difference between IEnumerable and IQueryable? IEnumerable is used for in-memory collections, while IQueryable is used for out-of-memory (like querying a database) collections. IQueryable is a subset of IEnumerable and allows LINQ-to-SQL, enabling deferred execution. 17. What is the difference between MVC and Web API in ASP.NET? MVC is a design pattern used to separate an application into three interconnected components: Model, View, and Controller. ASP.NET MVC is used to create web applications that return both views and data. Web API, on the other hand, is a framework for building HTTP services that can be accessed from any client, including browsers and mobile devices. It returns only data. 18. What is Dependency Injection? Dependency Injection (DI) is a design pattern that allows an object to receive its dependencies from outside rather than creating them internally. It promotes the principle of inversion of control and makes the system more modular and testable.
19. What is the Global Assembly Cache (GAC)?
The GAC is a machine-wide cache of assemblies that allows .NET applications to share libraries. Assemblies in the GAC are globally available to all .NET applications on the machine. 20. What is the difference between Task and Thread? A Thread represents an actual OS-level thread, with its own stack and kernel resources. A Task is a higher-level way to represent asynchronous operations, backed by a thread-pool thread. Tasks provide easier ways to handle concurrency and parallelism. 21. What is the AppDomain in .NET? An AppDomain is a logical container within a process where .NET applications run. It provides a layer of isolation, allowing multiple .NET applications to run within a single process without interfering with each other. 22. What is Reflection in .NET? Reflection is the ability of the .NET runtime to inspect the metadata of assemblies, modules, and types. It allows developers to get information about assemblies, classes, methods, and other types at runtime and also to create instances of types, invoke methods, and access fields and properties dynamically. 23. What is the difference between const, readonly, and static in C#? const: Represents a compile-time constant. Its value cannot be changed after declaration. readonly: Represents a runtime constant. Its value can be set only in the constructor and cannot be changed afterward. static: Represents a value or method that belongs to the type rather than an instance of the type. 24. What is the using statement in C#? The using statement is used to ensure that an object, which implements the IDisposable interface, gets disposed of properly when it is no longer needed. It ensures that resources are released, reducing the risk of resource leaks. 25. What is the difference between struct and class in C#? struct: Represents a value type, stored on the stack, and has a default value of zero or null. It does not support inheritance (except from System.ValueType). class: Represents a reference type, stored on the heap, and has a default value of null. It supports inheritance. 26. What is the virtual keyword in C#? The virtual keyword is used to declare a method, property, indexer, or event that can be overridden in derived classes. 27. What is the difference between abstract and interface in C#?
abstract: Represents a base class that cannot be instantiated and
may contain both abstract (without implementation) and non-abstract members.
interface: Represents a contract that classes or structs can
implement. It can only contain method signatures, properties, events, and indexers without any implementation. 28. What is the volatile keyword in C#?
The volatile keyword indicates that a field can be modified by multiple
threads simultaneously. It ensures that the most up-to-date value is present in the field at all times. 29. What is the dynamic keyword in C#? The dynamic keyword is used to bypass compile-time type checking. It allows variables to store any type of value and call any method or access any properties without compile-time checking. 30. What is the difference between throw and throw ex in exception handling?
throw: Re-throws the caught exception, preserving the original stack
trace. throw ex: Throws the exception but resets the stack trace to the current call.
31. What is an Attribute in .NET?
An attribute is a declarative tag that provides metadata about the program elements it describes (like classes, methods, properties, etc.). Attributes are used to add additional information to the program elements at compile time. 32. What is the purpose of the Main method in C#? The Main method is the entry point of a C# application. When the application is started, the Main method is the first method that gets executed. 33. What is the difference between == and Equals method in C#? == is an operator used for comparing the references of two objects, while the Equals method is used to compare the content of two objects. 34. What is the as keyword in C#? The as keyword is used for type casting. If the conversion is not possible, it returns null instead of throwing an exception. 35. What is the difference between early binding and late binding? Early binding (or static binding) occurs at compile time, where the type of the object is known. Late binding (or dynamic binding) occurs at runtime, where the type of the object is determined dynamically. 36. What is the out keyword in C#? The out keyword is used in method parameters to indicate that the method will return a value through that parameter. It is useful when a method needs to return multiple values. 37. What is Polymorphism? Polymorphism is a fundamental concept in object-oriented programming that allows objects of different types to be treated as if they were objects of the same type. It provides the ability to redefine methods in derived classes. 38. What is the difference between System.String and System.Text.StringBuilder classes? System.String is immutable, meaning its value cannot be changed once created. Every time you modify a string, a new instance is created. System.Text.StringBuilder is mutable and allows for efficient string concatenation and manipulation without creating multiple string instances. 39. What is the ‘is’ keyword in C#? The ‘is’ keyword is used to check if an object is of a specific type. It returns true if the object is of the specified type, otherwise false. 40. What is the purpose of the Dispose method in .NET? The Dispose method is used to release unmanaged resources like files, database connections, etc. It is a part of the IDisposable interface, which provides a mechanism to clean up resources explicitly. 41. What is the sealed keyword in C#? The sealed keyword is used to prevent a class from being inherited. It can also be used to prevent method overriding by marking methods in a class as sealed. 42. What is the difference between static and singleton classes? A static class cannot be instantiated and its members can be accessed directly without creating an object. A singleton class allows only one instance of itself to be created and provides a global point of access to that instance. 43. What is the params keyword in C#? The params keyword allows a method to accept a variable number of arguments. The arguments are passed as an array to the method. 44. What is the difference between explicit and implicit type casting? Explicit casting (type casting) requires the user to specify the target data type, and there's a risk of data loss. Implicit casting is done automatically by the compiler when there's no risk of data loss. 45. What is the lock keyword in C#? The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. It's used to ensure thread safety. 46. What is the difference between stack and heap memory? Stack memory is used for static memory allocation, and variables stored in the stack are known at compile time. Heap memory is used for dynamic memory allocation, and variables stored in the heap are determined at runtime. 47. What is the partial keyword in C#? The partial keyword allows a class, struct, or interface to be split into multiple files. All parts are combined during compilation to form a single class, struct, or interface. 48. What is the yield keyword in C#? The yield keyword is used in an iterator block to provide a value to the enumerator object or to signal the end of iteration. 49. What is the purpose of the ~ (tilde) operator in C#? The ~ operator is a bitwise complement operator. It inverts the bits of its operand. 50. What is the checked and unchecked keyword in C#? • The checked keyword is used to explicitly enable overflow checking for integral-type arithmetic operations and conversions. The unchecked keyword is used to explicitly disable overflow checking.