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 7

< Previous Page              Next Page >
Question: What are nullable types in C#?
Answer: Nullable types allow value types (such as int, float, etc.) to represent null values in addition to their normal range of values.
They are represented by adding a '?' after the data type declaration (e.g., int?).
Question: What is the difference between an abstract class and an interface in C#?
Answer: An abstract class can contain both abstract and concrete methods, while an interface only defines method signatures without any implementation.
A class can inherit from only one abstract class but can implement multiple interfaces. Additionally, abstract classes can have access modifiers, fields, and constructors, while interfaces cannot.
Question: What is garbage collection in C#?
Answer: The garbage collection is a process by which the .NET runtime automatically deallocates memory that is no longer in use by an application. It helps manage memory efficiently and prevents memory leaks by identifying and reclaiming unused objects.
Question: What is the difference between a static class and a singleton pattern in C#?
Answer: A static class cannot be instantiated and is typically used to group related methods and constants together, whereas a singleton pattern is a design pattern that ensures a class has only one instance and provides a global point of access to it.

Question: What is an extension method in C#?
Answer: An extension method is a static method that extends the functionality of existing types without modifying their source code. It allows additional methods to be called on objects of the extended type as if they were defined within the type itself, providing a convenient way to add new functionality to existing types.
Question: What is the 'var' keyword in C#?
Answer: The 'var' keyword is used to implicitly declare a variable with its type inferred from the assigned value. It is often used in situations where the type of the variable is obvious from the context, improving code readability and reducing redundancy.

Question: What is a tuple in C#??
Answer: A tuple in C# is a lightweight data structure that can hold multiple values of different types. It provides a convenient way to return multiple values from a method without defining a custom class or struct.
Tuples are immutable, meaning that their values cannot be changed after creation.

Question: What is the difference between 'File' and 'FileStream' classes in C# for file I/O operations?
Answer: The 'File' class in C# provides static methods for performing file I/O operations, such as reading/writing text from/to a file, copying/moving files, and deleting files.
'FileStream', on the other hand, is used to read from or write to a file sequentially or randomly with more control over file handling, such as setting file access mode, file sharing mode, and buffer size.

Question: What is the difference between 'HashSet' and 'List' in C#?
Answer: The 'HashSet' in C# is a collection that stores unique elements without duplicates, while 'List' is a collection that stores elements in a sequential order and allows duplicates.
'HashSet' provides constant-time complexity for common operations such as add, remove, and contains, while 'List' provides faster access to elements by index but slower lookup times for membership.

< Previous Page Next Page >