Ans: .NET Framework is a software development platform developed by Microsoft. It provides a runtime environment to create, deploy, and run applications, including libraries, languages, and tools for different programming languages.
Ans: CLR is the heart of the .NET Framework. It provides various services such as memory management, security, type safety, and exception handling. It also compiles and executes managed code into native code.
Ans: Managed code is written in languages like C#, VB.NET, etc., that run within the .NET Framework. Unmanaged code is written in languages like C++ and directly interacts with hardware and memory, without CLR's control.
Ans:
Ans: Value types store the actual value, while reference types store a reference to the value's memory location. Value types include primitive types like int, float, bool, etc., while reference types include classes, interfaces, delegates, etc.
Ans: Boxing is the process of converting a value type to an object type (e.g., int to object). Unboxing is the opposite operation, converting the object back to a value type.
Ans: Just-In-Time (JIT) compilation is the process where CLR converts Intermediate Language (IL) code to native machine code right before execution. This improves performance by allowing optimizations based on the actual environment.
Ans: Garbage Collection (GC) is the process of automatically managing memory by identifying and reclaiming memory occupied by objects that are no longer referenced by the program.
Ans: Finalize is a method called by the GC before an object is removed from memory. Dispose is a method used to release unmanaged resources early, implementing the IDisposable interface, and can be called explicitly by the programmer.
Ans: ASP.NET Web Forms is a framework for building web applications using a page-based model with controls. ASP.NET MVC is a pattern for designing web applications, separating concerns into Model, View, and Controller components.
Ans: MVC stands for Model-View-Controller. It's a design pattern where the application is divided into three components: Model (data and logic), View (user interface), and Controller (handles user input and coordinates between Model and View).
Ans: Both ViewData and ViewBag are used to pass data from Controller to View in ASP.NET MVC. ViewData uses a dictionary, while ViewBag uses dynamic properties. ViewBag provides a more concise syntax but lacks compile-time safety
Ans: Routing maps URLs to controller actions. It allows for creating user-friendly URLs that map directly to specific controller methods, enhancing SEO and usability.
Ans: Entity Framework is an Object-Relational Mapping (ORM) framework that simplifies database interaction by allowing developers to work with databases using .NET objects. It automates the mapping between objects and database tables.
Ans: Language Integrated Query (LINQ) is a set of features that allow developers to perform queries on collections and databases directly from C# code. It provides a unified syntax for querying different data sources.
Ans: ASP.NET supports various authentication methods:
Ans: ADO.NET is a data access technology that allows developers to connect to databases, retrieve and manipulate data using .NET objects. It includes classes like SqlConnection, SqlCommand, SqlDataAdapter, etc.
Ans:
Ans: Reflection allows you to inspect and manipulate metadata, types, and objects at runtime. It enables dynamic loading of assemblies, creating instances of types, and invoking methods without knowing them at compile time.
Ans: The GAC is a central repository for storing shared .NET assemblies that need to be accessible across multiple applications. Assemblies in the GAC have a strong name, ensuring versioning and security.
Ans: Serialization is the process of converting objects into a format that can be stored or transmitted and then reconstructing them back into objects. .NET provides Binary, XML, and JSON serialization.
Ans: Exception handling in .NET is managed using try-catch blocks. When an exception occurs, the runtime searches for an appropriate catch block to handle it. If none is found, the application terminates.
Ans: Delegates are type-safe function pointers that allow you to define and pass methods as arguments to other methods. They're commonly used for event handling and callbacks.
Ans: Events allow objects to notify other objects when something of interest happens. They are based on delegates and provide a way to implement the Observer pattern.
Ans: Multithreading allows an application to execute multiple threads concurrently, improving performance and responsiveness. .NET provides the Thread class and higher-level constructs like Tasks and async/await for asynchronous programming.
Ans: The "using" statement is used for automatic resource management, especially for objects that implement IDisposable. It ensures that the object's Dispose method is called, freeing up resources.
Ans: The "as" operator is used for safe type casting. If the conversion fails, it returns null instead of throwing an exception.
Ans: The "is" operator is used to check whether an object is of a specified type. It returns a boolean value indicating the result of the type check.
Ans:
Ans: Code Access Security is a security model in .NET that controls the permissions of code based on the source of the code, the identity of the user, and other factors. It ensures that code can only access resources it has permission to access.
Ans:
String: Immutable, concatenation creates new instances, less efficient for frequent modifications.
StringBuilder: Mutable, designed for efficient string concatenation and modification.
Ans: The "readonly" keyword is used to declare constants that are evaluated at runtime, but their values can't be modified after initialization.
Ans: IoC is a design principle where control over object creation and lifecycle is shifted from the application to a container. DI is a technique used to implement IoC, where a class's dependencies are injected through constructor parameters or properties.
Ans:
Shallow Copy: Copies references, not actual objects. Changes in the original reflect in the copy.Ans: The "volatile" keyword is used to indicate that a field's value may change at any time, preventing the compiler from performing certain optimizations.
Ans: The "yield" keyword is used to create iterator methods that return a sequence of values. It simplifies the process of creating iterators by automatically generating state machine code.
Ans: The Dispose Pattern is used to release unmanaged resources and perform cleanup operations when an object is no longer needed. It involves implementing the IDisposable interface and calling Dispose() explicitly.
Ans:
"throw": Rethrows the current exception while maintaining the original call stack.
"throw ex": Rethrows the current exception, but the original call stack is lost, making debugging more challenging.
Ans: Asynchronous programming allows you to perform non-blocking operations, ensuring that the application remains responsive. This is achieved using the "async" and "await" keywords.
Ans: A Tuple is a lightweight data structure that allows you to store a sequence of heterogeneous elements. Tuples are commonly used when you need to return multiple values from a method.
Ans: Extension methods allow you to add new methods to existing types without modifying their source code. They're particularly useful for adding utility methods to framework classes.
Ans: The Null Conditional Operator is used to safely access members of an object without causing a null reference exception. If the object is null, the expression evaluates to null.
Ans: Indexers allow objects to be indexed just like arrays, enabling custom data access mechanisms for objects.
Ans: The "params" keyword allows you to pass a variable number of parameters to a method, which are treated as an array within the method's body.
Ans:
Value Type: Holds the actual value and is stored on the stack. Examples include int, float, and struct.
Reference Type: Holds a reference to the value's memory location and is stored on the heap. Examples include classes, interfaces, and delegates.
Ans: Anonymous types allow you to create objects without explicitly defining a class. They are useful for ad-hoc data structures.
Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.
Ans: Web services have file extension .asmx..
Ans:
Static Class: Cannot be instantiated, contains only static members.
Singleton Class: Instantiated only once, typically via a static property or method, and maintains a single instance throughout the application.
Ans: The "using" directive is used to import namespaces so that you can use types from those namespaces without fully qualifying their names.
Ans: Attributes provide metadata about program entities, such as classes, methods, and properties. They're used for adding information that can be retrieved at runtime using reflection.
Ans: Reflection.Emit is a part of the Reflection namespace that allows you to generate and define new types, fields, methods, and other constructs at runtime.
Ans: Partial classes allow a single class to be defined across multiple source files. This is especially useful when a class is large and has parts that are generated or maintained automatically.
Ans: Extension methods allow you to add new methods to existing types without modifying their source code. They're particularly useful for adding utility methods to framework classes.
Q55. What is Lazy Initialization in C#?
Ans: Lazy initialization is a design pattern that defers the creation of an object until the first time it's needed. It's useful for improving performance by only creating objects when they're actually required.
Ans: The "params" keyword allows you to pass a variable number of arguments to a method by using an array-like syntax.
Ans: Object pooling is a technique used to manage and reuse objects to improve performance, especially for objects with high instantiation and disposal costs.
Ans: Type conversion involves changing the type of a value from one type to another. It can be implicit (automatic) or explicit (manual) using casting.
Ans: Dynamic binding allows you to defer the resolution of method calls, property access, and other operations until runtime. This is achieved using the "dynamic" keyword.
Ans: The "nameof" operator returns the name of a variable, type, or member as a string. It's helpful for avoiding hard-coded strings when working with reflection.
Ans: Finalization refers to the process of cleaning up an object before it's destroyed by the garbage collector. It involves implementing a finalizer method using the destructor syntax.
Ans:
Covariance: Allows you to use a more derived type for a delegate or interface method's return type.
Contravariance: Allows you to use a less derived type for a delegate or interface method's parameter type.
Ans: The "volatile" keyword indicates to the compiler that a variable's value may change at any time by external means. This prevents certain optimizations that could lead to incorrect behavior.
Related Interview Questions...
ASP.Net Web API Essentials using C# Interview Questions
VB.NET Interview Questions and Answers
ASP.NET MVC Interview Questions and Answers
ASP.NET Interview Questions and Answers For Experienced
ASP.NET Interview Questions and Answers