Reference Page: C-Language|C++|C#|VB.Net|Asp.Net

C# Links : Learn     Interview Questions     Software IDE C# jobs : Indeed.com     ZipRecruiter.com     Monster.com

C# Interview Questions - Page 3

< Previous Page              Next Page >
Question: What is the purpose of the 'finally' block in C# exception handling?
Answer: The 'finally' block is used to define code that should always be executed, regardless of whether an exception occurs or not.
It is commonly used for cleanup tasks, such as closing file handles or releasing resources, ensuring that they are properly handled even in the event of an exception.

Question: Can you explain the concept of polymorphism in C# with an example?
Answer: In object oriented programming polymorphism is the ability of objects to be treated as instances of their base class or interface, even when they are instances of derived classes. An example of polymorphism in C# is method overriding, where a derived class provides its own implementation of a method defined in its base class.

For instance, consider a base class 'Shape' with a virtual method 'Draw', which is overridden by derived classes like 'Circle' and 'Rectangle' to provide specific drawing implementations for each shape.

Question: What are indexers in C#?
Answer: The indexers allow instances of a class or struct to be accessed like arrays, using square brackets to specify an index value.
They provide a way to encapsulate the internal representation of a collection and provide controlled access to its elements.

Question: What is the 'yield' keyword used for in C#?
Answer: The 'yield' keyword is used in iterator methods to enable the deferred execution of a sequence of values. It allows the method to return each element of the sequence one at a time, pausing execution until the next element is requested.

Question: What is the purpose of the 'using' directive in C#?
Answer: The 'using' directive is used to import namespaces, allowing types and members from those namespaces to be referenced directly in code without fully qualifying their names.

It helps simplify code and improve readability by reducing the need for explicit namespace references.

Question: What is 'dependency injection' in C#?
Answer: The dependency injection is a design pattern in which the dependencies of a class are provided to it externally rather than created internally.
Dependency injection helps to improve modularity, testability, and maintainability by decoupling classes from their dependencies and allowing them to be easily replaced or modified.

Question: What is Jagged Array in C#?
Answer: A jagged array is an array whose elements are arrays, possibly of different sizes. A jagged array is sometimes called an "array of arrays".
Its elements are reference types and are initialized to null.
Question: What is the difference between a 'class' and a 'struct' in C#?
Answer: A class is a reference type, while a struct is a value type.
Classes are typically used for complex data structures and support inheritance, polymorphism, and garbage collection. Structs are used for lightweight data structures and are passed by value, making them more efficient for small, frequently used objects.


< Previous Page Next Page >