Search

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, June 11, 2023

Infosys interview questions for Freshers .Net developers

 

Infosys interview questions for Freshers .Net developers


1. Garbage Collector in C#:

The garbage collector in C# is a part of the .NET runtime that automatically manages memory by reclaiming memory occupied by objects that are no longer in use. It tracks object references, identifies unused objects, and frees up memory for future allocations.


2. CLR (Common Language Runtime): 

CLR is the execution environment in the .NET framework that provides various services such as memory management, exception handling, security, and code execution. It compiles and manages code written in different .NET languages into a common intermediate language (CIL) and executes it.


3. Difference between String and StringBuilder: 

In C#, a String is an immutable sequence of characters, meaning it cannot be modified once created. StringBuilder, on the other hand, is a mutable class that allows efficient modification of strings by appending, inserting, or replacing characters without creating new instances.


4. Enum Keyword: 

The enum keyword in C# is used to declare an enumeration, which is a distinct type representing a set of named constants. It provides a way to define a group of related values that can be assigned to a variable, improving code readability and maintainability.


5. Enum Value Types: 

Yes, enum values in C# are value types. Each enumerated value represents a named constant of the enum type, and they are internally represented as integer values.


6. Managed Code and Unmanaged Code:

Managed code refers to code that runs within the managed environment of the CLR. It is written in languages such as C# or VB.NET and benefits from automatic memory management, security enforcement, and exception handling. Unmanaged code, on the other hand, is typically written in languages like C or C++ and runs outside the CLR's control, without the same level of automatic memory management and other managed code benefits.


7. Difference between Generic and Non-Generic: 

In C#, generics provide a way to create reusable, type-safe code that works with multiple data types. Generic classes, methods, and interfaces can be parameterized with specific types, allowing for greater flexibility and code reusability. Non-generic counterparts, on the other hand, are not type-safe and typically operate on a specific data type without the flexibility of working with different types.


8. Namespace for Generic: 

The System.Collections.Generic namespace in C# contains classes and interfaces for generic collections, such as List<T>, Dictionary<TKey, TValue>, etc.


9. Namespace for Non-Generic: 

The System.Collections namespace in C# contains classes and interfaces for non-generic collections, such as ArrayList, Hashtable, etc.


10. Example for Generic: 

An example of a generic class in C# is List<T>. It allows you to create a list that can hold elements of any specific type, such as List<int>, List<string>, List<Person>, etc.


11. Difference between Dictionary and DataTable: 

  • Dictionary is a generic collection that stores key-value pairs, allowing efficient lookup of values based on keys. It is typically used when you need fast access to elements based on unique keys.
  • DataTable, on the other hand, is a tabular representation of data that can hold multiple rows and columns. It is commonly used for storing and manipulating structured data, similar to a database table.


12. Difference between Function Overloading and Function Overriding:

  • Function Overloading: Function overloading in C# allows multiple methods in a class to have the same name but with different parameters. The compiler distinguishes between the overloaded methods based on the number, types, and order of the parameters.
  • Function Overriding: Function overriding occurs in inheritance when a derived class provides its own implementation of a method that is already defined in its base class. The overridden method in the derived class should have the same signature as the base class method.


13. Two Keywords for Function Overriding: The two keywords

used for function overriding in C# are "override" and "virtual". The base class method that can be overridden is marked with the "virtual" keyword, and the derived class method that overrides it is marked with the "override" keyword.


14. Use of "using" Keyword in C#: 

The "using" keyword in C# is used to define a scope within which a specific resource is used. It ensures that the resource is properly disposed of, even if an exception occurs, by implementing the IDisposable interface. It is commonly used with objects that access external resources, such as database connections or file streams.


15. Difference between Array and ArrayList:

Array: In C#, an array is a fixed-size collection of elements of the same type. The size of an array is determined at the time of its creation and cannot be changed. Arrays provide fast access to elements by their index.

ArrayList: ArrayList is a non-generic collection in C# that can dynamically grow or shrink in size. It can hold elements of different types and provides methods for adding, removing, and accessing elements. However, it is slower compared to arrays due to boxing and unboxing operations.


16. Difference between "is" and "as" Keyword: 

  • "is" keyword in C# is used for type checking. It checks if an object is of a specified type and returns a boolean value (true or false).
  • "as" keyword in C# is used for type casting. It attempts to cast an object to a specified type. If the cast is successful, it returns the cast object; otherwise, it returns null.


17. Extension Method: 

An extension method in C# allows you to add new methods to existing types without modifying their original implementation or creating a new derived type. It is defined as a static method in a static class and must be in the same namespace as the extended type. Extension methods are called as if they were instance methods of the extended type.


18. Sealed Class: 

  • A sealed class in C# is a class that cannot be inherited.
  •  It is marked with the "sealed" keyword.
  • Sealing a class prevents it from being used as a base class for other classes.
  •  Sealed classes are used when you want to restrict further inheritance and maintain the integrity of the class's implementation.

19. Multiple Try-Catch Blocks in C#: 

Yes, it is possible to use multiple try-catch blocks in C#. Each try block can be followed by one or more catch blocks that handle specific types of exceptions. This allows you to handle different exceptions separately and perform specific actions based on the exception type.


20. Difference between "==" Operator and "Equals" Method in C#: 

  • The "==" operator in C# is used for equality comparison between two variables. For value types, it compares the actual values, while for reference types, it compares the references (memory addresses) of the objects.
  • The "Equals" method in C# is a method defined in the Object class that can be overridden in derived classes. It is used to compare the equality of two objects based on their values or properties. The behavior of the "Equals" method can be customized based on the class's implementation.


21. Access Modifiers in C#: 

The access modifiers in C# determine the accessibility or visibility of types and members (fields, methods, properties, etc.). The main access modifiers are:

  1. public: The type or member is accessible from any code.
  2. private: The type or member is accessible only within the containing class.
  3. protected: The type or member is accessible within the containing class and its derived classes.
  4. internal: The type or member is accessible within the same assembly (project or DLL).
  5.  protected internal: The type or member is accessible within the same assembly and its derived classes, both inside and outside the assembly.


22. Use of "FirstOrDefault"

In LINQ: The "FirstOrDefault" method in LINQ is used to retrieve the first element of a sequence that satisfies a specified condition. If no element matches the condition, it returns the default value for the type, such as null for reference types or 0 for numeric types. It is commonly used to avoid null reference exceptions when accessing the first element of a sequence.


23. Default Database in SQL Server: 

The default database in SQL Server refers to the initial database that is used when a user connects to the SQL Server instance. The default database can be specified for each user, and it determines the database where the user's queries and operations are performed by default.

In SQL Server, the default databases that are commonly available include:

  1.  master: The master database stores system-level information and configuration settings. It records information about all other databases and is crucial for the functioning of the SQL Server instance.
  2. tempdb: The tempdb database is used to store temporary objects such as temporary tables, global temporary tables, and temporary stored procedures. It is recreated every time SQL Server starts.
  3. model: The model database serves as a template for creating new databases. When a new database is created, it is initialized with the contents of the model database.
  4.  msdb: The msdb database stores information related to SQL Server Agent, including jobs, alerts, operators, and backup and restore history. It is used for managing scheduling, maintenance plans, and other administrative tasks.

These are the default databases commonly found in SQL Server installations. However, it's worth noting that additional user-defined databases can be created as per specific requirements.


24. Primary Key in SQL: 

In SQL, a primary key is a column or a set of columns that uniquely identifies each row in a table. It ensures the uniqueness and integrity of the data in the table. The primary key constraint enforces the uniqueness and non-nullability of the specified column(s).


25. Difference between Primary Key and Foreign Key:

Primary Key: A primary key is a column or a set of columns in a table that uniquely identifies each row. It ensures the uniqueness and integrity of the data within the table.

Foreign Key: A foreign key is a column or a set of columns in a table that establishes a relationship with the primary key of another table. It creates referential integrity between two tables and enforces data consistency and integrity across the tables.


26. Use of Null Value in Primary Key: 

In SQL, a primary key column cannot contain a null value. It must have a unique and non-null value for each row, as it is used to identify each record uniquely.

No comments:

Post a Comment