banner-image

4.6 Created by potrace 1.15, written by Peter Selinger 2001-2017

5.0 Created by potrace 1.15, written by Peter Selinger 2001-2017

4.6 Created by potrace 1.15, written by Peter Selinger 2001-2017

.Net Interview Questions .Net FAQ


Hi, Welcome to Monopoly IT Solutions, our Interview Questions / FAQs can be very helpful for interview preparation in several ways:

  • Understanding the way how Questions are asked by interviewer
  • Practicing Answers, find our appropriate ways of answeringand excel the interview
  • Gaining Insight into the industry standard
  • Reducing Anxiety of Interview
  • Self analysis of Key Skills

Following are the conceptual theory questions

  • NET is a developer platform to build a variety of applications for web, mobile, desktop, and IoT. It supports various languages like C#, F#, Visual Basic, J#, C++, etc. for building applications.

  • The .NET framework is a software development platform that supports an object-oriented approach. It offers services, like memory management, networking, security, and type safety.

  • Just-In-Time compiler (JIT) is a part of Common Language Runtime (CLR) in .NET which is responsible for managing the execution of .NET programs regardless of any .NET programming language. A language-specific compiler converts the source code to the intermediate language.

  • Simula was the first OOP language and Java, JavaScript, Python, C++, Visual Basic. NET, Ruby, Scala, PHP are few others.

  • Types of Classes in C#
    • Abstract Class
    • Partial Class
    • Sealed Class
    • Static Class

  • In C# virtual method is a strategy that can be reclassified in derived classes. We can implement the virtual method in the base class and derived class. It is utilized when a method’s fundamental work is similar but in some cases derived class needed additional functionalities. A virtual method is declared in the parent class that can be overridden in the child class. We make a virtual method in the base class by using the virtual keyword and that method is overridden in the derived class using the Override keyword.

  • Modifiers are keywords that define the accessibility of a member, class, or datatype in a program. These are mainly used to restrict unwanted data manipulation by external programs or classes. There are 4 access modifiers (public, protected, internal, private) which defines the 6 accessibility levels as follows:
    • public
    • private
    • private protected
    • protected
    • internal
    • protected internal

  • Generally, the file is used to store the data. The term File Handling refers to the various operations like creating the file, reading from the file, writing to the file, appending the file, etc. There are two basic operations that are mostly used in file handling is reading and writing of the file. The file becomes stream when we open the file for writing and reading.

  • An exception is an error that happens at runtime. Using C#’s exception-handling subsystem, we can, during a structured and controlled manner, handle runtime errors. The primary advantage of exception handling is that it automates much of the error handling code.
    • Array Type Mismatch Exception: This exception comes when the Type of value being stored is incompatible with the type of the array.
    • Divide By Zero Exception: It comes when the user tries to division an integer value by zero.
    • Index Out Of Range Exception: When an array index is out-of-bounds, it exception occurred.
    • Invalid Cast Exception: A runtime cast is invalid.
    • Out Of Memory Exception: Insufficient free memory exists to continue program execution.
    • Overflow Exception: An arithmetic overflow occurred.
    • Null Reference Exception: An attempt was made to operate on a null reference—that is, a reference that does not refer to an object.

  • CTS stands for Common Type System.It is used to convert the code from one programming to another programming(ex:.net to vb.net , F#)

  • It also helps in the management of code, as code that targets the runtime is known as the Managed Code, and code that doesn’t target to runtime is known as Unmanaged code.
  • Code which runs under CLR environment is called Managed Code.
  • Unmanaged code does not depend on CLR for execution and is developed using languages outside the .NET framework.

  • Garbage Collection in .NET Framework facilitates automatic memory management. It automatically releases the memory space after all the actions related to the object in the heap memory are completed.

  • Console.Read() will read the input from console in the form of string and returns int.
  • Console.ReadLine() will read the input from console in the form of string and returns string.
  • Console.ReadKey() will accept character and return ASCII value of that character.

  • A class can be understood as a template or a blueprint, which contains some values, known as member data or member, and some set of rules, known as behaviours or functions. So when an object is created, it automatically takes the data and functions that are defined in the class.
  • Therefore the class is basically a template or blueprint for objects. Also one can create as many objects as they want based on a class.
  • For example, first, a car’s template is created. Then multiple units of car are created based on that template.

  • An object refers to the instance of the class, which contains the instance of the members and behaviors defined in the class template. In the real world, an object is an actual entity to which a user interacts, whereas class is just the blueprint for that object. So the objects consume space and have some characteristic behavior. For example, a specific car

  • OOP is the acronym for Object-Oriented Programming. It is a programming structure that uses self-contained entities called ‘objects’ instead of methods to achieve the desired functionality. OOP allows .NET developers to create modular programs and classes containing methods, properties, fields, events, and other logical modules.

  • The basic features of OOP are
    • Encapsulation: Creation of self-contained modules that bind together the data and the functions that access that data.
    • Abstraction: Handles complexity and allows the implementation of further complex logic without disclosing it to the user object.
    • Polymorphism: Operation performed depends upon the context at runtime to facilitate easy integration.
    • Inheritance: Creation of classes in a hierarchy to enable a class to inherit behaviour from its parent class allowing reuse of code.

  • So Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details.
    • Data hiding: Encapsulation is the process of hiding unwanted information, such as restricting access to any member of an object.
    • Data binding: Encapsulation is the process of binding the data members and the methods together as a whole, as a class

  • Polymorphism is composed of two words - “poly” which means “many”, and “morph” which means “shapes”. Therefore Polymorphism refers to something that has many shapes

  • The term “inheritance” means “receiving some quality or behavior from a parent to an offspring.” In object-oriented programming, inheritance is the mechanism by which an object or class (referred to as a child) is created using the definition of another object or class (referred to as a parent). Inheritance not only helps to keep the implementation simpler but also helps to facilitate code reuse.

  • If you are a user, and you have a problem statement, you don't want to know how the components of the software work, or how it's made. You only want to know how the software solves your problem. Abstraction is the method of hiding unnecessary details from the necessary ones. It is one of the main features of OOPs

  • No. An object is necessary to be created if the base class has non-static methods. But if the class has static methods, then objects don’t need to be created. You can call the class method directly in this case, using the class name.

  • Constructors are special methods whose name is the same as the class name. The constructors serve the special purpose of initializing the objects. For example, suppose there is a class with the name “MyClass”, then when you instantiate this class, you pass the
    syntax :- MyClass myClassObject = new MyClass();

  • A Destructor is used to free the dynamically allocated memory and release the resources. It is instantly invoked when the Object is destroyed.

  • Yes, one can restrict an Object Creation by using the following methods-
  • Abstract Class, Static Class, Private or Protected Constructor.

  • Encapsulation is wrapping, it's just hiding properties and methods.
  • Encapsulation is used for hiding the code and data in a single unit to protect the data from the outside world.
  • Class is the best example of encapsulation.
  • Abstraction refers to showing only the necessary details to the intended user.

  • No, an abstract class cannot be a sealed class.
  • Because, the sealed modifier prevents a class from being inherited and the abstract modifier requires a class to be inherited.

  • It is used to pause the object curation of a class. This is used in Singleton Class. It can be used to stop a class from being inherited.

  • No, it is impossible to inherit Enum in C# because the Enums are by default sealed.

  • Encapsulation
    • Encapsulation is the process or method of containing the information in a single unit and providing this single unit to the user.
    • Main feature: Data hiding. It is a common practice to add data hiding in any real-world product to protect it from the external world. In OOPs, this is done through specific access modifiers
    • Encapsulation hides data and the user cannot access the same directly
    • Encapsulation focus is on “How” it should be done
  • Abstraction
    • Abstraction is the process or method of gaining information
    • Main feature: reduce complexity, promote maintainability, and also provide a clear separation between the interface and its concrete implementation
    • Abstraction provides access to specific parts of data
    • Abstraction focus is on “what” should be done

  • Abstract Class
    • It contains both declaration and implementation parts.
    • Multiple inheritance is not achieved by abstract class
    • It contains constructor
    • It can contain static members
  • Interface
    • It contains only the declaration of methods, properties, events, or indexers. Since C# 8, default implementations can also be included in interfaces.
    • Multiple inheritance is achieved by interface.
    • It does not contain constructors
    • It does not contain static members

  • Overriding means changing the functionality of a method without changing the signature.
  • You can override a method in the base class by creating a similar method in the derived class. This can be done by using virtual/override keywords.
    • virtual:allows the method to be overridden by the derived class
    • override:indicates the method is overriding the method from the base class

  • Exception handling in C# is a mechanism to handle runtime errors and gracefully recover from them or display meaningful error messages to the users. It can be implemented using try, catch, and finally blocks.
    • try: The code that might throw an exception is placed inside the try block. If an exception occurs within the try block, the execution is transferred to the appropriate catch block.
    • catch: The catch block is used to handle the exception that occurred in the try block. You can have multiple catch blocks to handle different types of exceptions.
    • finally: This block contains code that must be executed regardless of whether an exception was thrown or not. It is typically used for clean-up tasks, such as closing file handles or database connections.

  • ADO.NET stands for ActiveX Data Objects. It is a major component of the .NET framework. It is designed to connect with different databases like SQL, MySQL, Oracle, and MS Access, etc.

  • Connection pooling contains database collections so that the connection can be used or reused whenever there is a request to the database.

  • DataView is used to represent a whole table or a part of the table. It is used for sorting and searching data in the data table.

  • ExecuteScalar: It returns a single value from the dataset.
  • ExecuteNoQuery: It has multiple values and returns result set from the dataset.
  • ExecuteReader: Forward-only Result set.
  • ExecuteXMLReader: Build XML Reader object from the SQL Query.

  • OLEDB is a data provider which basically works on various data sources. SQL Client is also a provider that is specifically designed for Microsoft SQL Server.

  • Data Binding in ADO.NET is the process that establishes a connection between the application UI and business logic.

  • Serialization is the technique for changing an item into a byte of stream which can be put away and communicated over the organization.

  • Following are three layers
    • Presentation Layer
    • Business Logic Layer
    • Database Access Layer

  • A linked server enables the SQL server to implement commands against OLE DB data sources on remote servers.

  • LINQ (Language Integrated Query)
    LINQ is known as Language Integrated Query and it is introduced in . NET 3.5 and Visual Studio 2008. The beauty of LINQ is it provides the ability to . NET languages(like C#, VB.NET, etc.) to generate queries to retrieve data from the data source.

  • Advantages of LINQ
    • Compile-time error checking.
    • Complex problems are easy to debug.
    • Easy to understand....
    • LINQ expressions are strongly typed.

  • Types of LINQ
    • LINQ to Objects
    • LINQ to XML
    • LINQ to Dataset
    • LINQ to SQL
    • LINQ to Entities

  • Where clause : It allows adding some conditional filters to the query.
  • Let clause : It allows defining a variable and assigning it a value calculated from the data values.

  • The query expression is a query expressed in the query syntax. It holds information for sorting, filtering, grouping, or joining to apply to the source code.

  • Two methods
    • Expression Syntax or Query Syntax
    • Method Extension Syntax or the Method Syntax.

    • Language Extensions
    • LINQ Providers
    • Standard Query Operators.

  • The anonymous function is defined as the function without any name. We only specify the parameters in the anonymous function and build the code in curly braces

  • The architecture of LINQ is 3-layered architecture. In which the topmost layer contains language extension and the bottom layer contains data sources that generally object implementing IEnumerable < T> or IQueryable < T> generic interfaces.

  • A lambda expression is a short block of code which takes in parameters and returns a value.

  • Entity Framework is an ORM (Object-Relational Mapping) framework. It enables developers to work with databases using .NET objects and eliminates the need for most of the data-access code that developers usually need to write.

  • Entity refers to a class that maps to a table in a relational database. Entities are the objects that EF manages for you, allowing you to interact with the database in an object-oriented manner rather than writing SQL queries directly.

  • Entity Framework supports three different approaches:
    • Database-First: Creates entity classes based on an existing database schema.
    • Model-First: Allows creating entity classes and relationships visually in the EDMX designer.
    • Code-First: Enables developers to define entities, relationships, and configurations using code.

  • A foreign key relationship in the database is represented by the navigation property supported by the Entity Framework. It is possible to specify relationships between entities in a database using this property type. Relationships are defined in a way as to remain coherent in object-oriented code.

  • Migrations in Entity Framework Core allow developers to evolve the database schema over time in a structured way. They enable creating, updating, and reverting database schema changes, keeping the database schema in sync with the application's data model.

    • Advantages: Rapid development, reduced amount of boilerplate code, easy to maintain, supports various database providers, LINQ support for querying data.
    • Disadvantages: Performance overhead, potential for generating inefficient queries, complexity in some advanced scenarios, learning curve.

  • Entity Framework's performance is enhanced by following these steps:
    • Choose the right collection for data manipulation.
    • Do not put all DB objects into one entity model.
    • When the entity is no longer required, its tracking should be disabled and altered.
    • Use pre-generating Views to reduce response time for the first request.
    • Don't fetch all fields unless needed.
    • Optimize and debug LINQ queries.
    • Whenever possible, use compiled queries.

  • The DbContext class in Entity Framework represents the session with the database and provides a set of APIs to perform CRUD (Create, Read, Update, Delete) operations on entities. It also manages the entity objects during their lifecycle.

    • Lazy Loading: Lazy loading is the technique where related entities are loaded from the database only when they're accessed for the first time. It's the default behaviour in Entity Framework Core, and it helps in avoiding unnecessary database calls.
    • Eager Loading: Eager loading is the technique where related entities are loaded along with the main entity using the Include method or using projection. It reduces the number of database round trips but might fetch unnecessary data.

    • Lazy Loading: Lazy loading is the technique where related entities are loaded from the database only when they're accessed for the first time. It's the default behaviour in Entity Framework Core, and it helps in avoiding unnecessary database calls.
    • Eager Loading: Eager loading is the technique where related entities are loaded along with the main entity using the Include method or using projection. It reduces the number of database round trips but might fetch unnecessary data.

  • The SaveChanges() method in EF always wraps any operation involving inserting, updating, or deleting data into a transaction. Hence, you do not have to explicitly open the transaction scope.

    • CSDL: This stands for Conceptual Schema Definition Language. Basically, it's a conceptual abstraction that is exposed to the application. In this file, you will find a description of the model object.
    • SSDL: This stands for Storage Schema Definition Language. In this section, we define the mapping to our RDBMS data structure.
    • MSL: This stands for Mapping Schema Language. SSDL and CSDL are connected by it. It bridges the gap between the CSDL and SSDL or maps the model and the storage.

    • Dbset- operations can be created, updated, read, and deleted on any entity set in a dbset class. We must include the dbset type properties mapping to the database tables and views in the context class (from dbcontext).
    • Dbcontext- It is an important class in Entity Framework API. This is used to connect a domain class or entity and the database. Its main responsibility is to communicate with the database.

  • Database concurrency arises when multiple users are accessing and modifying the same data simultaneously in the same database. And the concurrency controls are the systems by which the consistency of data is protected in such situations.

  • We can implement optimist locking to handle the database concurrency. We can implement the locking by right-clicking on the EDMX designer and setting the concurrency model to Fixed. If any concurrency issue exists, a positive concurrency exception error arises.

    • A few data layer codes are created by Ado.Net that Entity Framework doesn't create.
    • Entity Framework, unlike ADO.Net, generates code for intermediate layers, data access layers, and mappings automatically. This results in a reduction in development time.
    • On a performance basis, ADO.Net is more efficient and faster than Entity Framework.

  • POCO stands for 'Plain Old CLR Objects'. POCO classes are just like other normal .NET classes as these classes don't depend on any framework-specific base class, unlike the standard .NET class. It LINQ queries, which are supported by entities derived from the Entity Object itself. Both EF 6 and EF Core support POCO entities.

  • ObjectSet is generally considered as a specific type of data set that is commonly used to read, update, create, and remove operations from existing entities. Only the ObjectContext instance can be used to create it. No Entity SQL method is supported by it.

  • SQL injection is a method that hackers use to access sensitive information from an organization's database. This application-layer attack is the result of inappropriate coding in our applications, allowing hackers to inject SQL statements into your SQL code. The most common cause of SQL Injection is that user input fields allow SQL statements to pass through and directly query the database. ADO.NET Data Services queries are commonly affected by SQL Injection issues.

  • The injection-proof nature of Entity Framework lies in the fact that it generates parameterized SQL commands that help prevent our database from SQL injections. By inserting some Malicious inputs into queries and parameter names, one can generate a SQL injection attack in Entity SQL syntax. It is best to never combine user inputs with Entity SQL commands text to prevent or avoid this problem.

Following are the coding based questions

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • 
                            
                            

  • *
    * *
    * * *
    * * * *
    
                            
                            

  • 1
    1 2
    1 2 3
    1 2 3 4
    
                            
                            

  • 1
    2 2
    3 3 3
    4 4 4 4
    
                            
                            

  • 1
    2 3
    4 5 6
    7 8 9 10
    
                            
                            

  • 1
    2 3
    4 5 6
    7 8 9 10
    
                            
                            

  • *
    * *
    * * *
    * * * *
    
                            
                            

getintouch

Book for Live Demo!