0% found this document useful (0 votes)
14 views

CSharp Interview Questions

c#

Uploaded by

rpillaiabhinav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

CSharp Interview Questions

c#

Uploaded by

rpillaiabhinav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Frequently Asked C# Interview Questions for Freshers

1. What is C# and its key features?


C# (C-sharp) is a modern, object-oriented programming language developed by Microsoft
within its .NET initiative. Key features include simplicity, modern programming practices,
object-oriented, type-safety, scalability, component orientation, structured programming,
and interoperability with other languages.

2. What is the difference between `ref` and `out` parameters in C#?


The `ref` keyword indicates that a parameter is passed by reference and must be initialized
before being passed. The `out` keyword also indicates a parameter passed by reference but
does not require initialization before being passed; it must be assigned a value within the
method.

3. What are Value Types and Reference Types in C#?


Value types hold their value directly, and examples include `int`, `char`, and `float`.
Reference types store references to their data, examples include `class`, `interface`,
`delegate`, and `string`.

4. Explain the concept of Garbage Collection in C#.


Garbage Collection (GC) in C# is an automated memory management feature that reclaims
memory occupied by objects that are no longer in use, preventing memory leaks and
optimizing performance.

5. What is an Interface in C#?


An interface in C# is a contract that defines a set of methods and properties without
implementing them. Classes and structs that implement the interface must provide an
implementation for the interface's members.

6. What is Inheritance in C#?


Inheritance is an object-oriented programming concept where a class (derived class)
inherits properties and methods from another class (base class), promoting code reusability
and polymorphism.

7. What is Polymorphism in C#?


Polymorphism is the ability of different classes to be treated as instances of the same class
through a common interface or base class, allowing methods to be used interchangeably
and promoting flexibility and maintainability.
8. What is Encapsulation in C#?
Encapsulation is an object-oriented programming principle that restricts access to certain
components of an object, protecting its internal state and allowing access only through
public methods, ensuring data integrity and security.

9. What are Properties in C#?


Properties in C# are members that provide a flexible mechanism to read, write, or compute
the values of private fields. They use get and set accessors to control the accessibility of the
fields.

10. What is the difference between `abstract` class and `interface` in C#?
An `abstract` class can have implementations for some of its members but cannot be
instantiated. An `interface` only defines members without any implementation. Classes can
inherit from multiple interfaces but only from one abstract class.

11. What is the `virtual` keyword in C#?


The `virtual` keyword is used to modify a method, property, indexer, or event declaration
and allow it to be overridden in a derived class, enabling polymorphism.

12. What are Delegates in C#?


Delegates are type-safe pointers to methods that allow methods to be passed as parameters.
They are used to define callback methods and implement event handling.

13. What is an Exception in C#?


An exception is a runtime error that disrupts the normal flow of execution. C# provides a
structured exception handling mechanism using `try`, `catch`, `finally`, and `throw`
keywords.

14. What is the difference between `throw` and `throw ex` in C#?
`throw` rethrows the original exception, preserving the original stack trace, while `throw ex`
throws the current exception, resetting the stack trace and losing the original error context.

15. What are Generics in C#?


Generics allow you to define type-safe data structures without committing to actual data
types. They provide code reusability, type safety, and improved performance by allowing
classes, methods, and interfaces to operate with any data type.

16. What is LINQ in C#?


Language Integrated Query (LINQ) is a set of features in C# for querying collections using a
consistent syntax. It allows queries to be written directly within C# code, enabling
integration with various data sources like databases, XML, and collections.
17. What are Anonymous Types in C#?
Anonymous types allow you to create objects without explicitly defining a class. They are
useful for encapsulating a set of read-only properties into a single object without having to
define a separate class.

18. What is the difference between `const` and `readonly` in C#?


`const` is a compile-time constant, meaning its value must be assigned at declaration and
cannot be changed. `readonly` is a runtime constant, meaning its value can be assigned at
declaration or within a constructor but cannot be changed thereafter.

19. What is the purpose of the `using` statement in C#?


The `using` statement ensures that `IDisposable` objects are properly disposed of, releasing
any resources they hold. It provides a convenient syntax to manage resource cleanup
automatically.

20. What is the difference between `Array` and `ArrayList` in C#?


`Array` is a fixed-size collection of elements of the same type. `ArrayList` is a dynamic array
that can hold elements of any type and can grow or shrink as needed. However, `ArrayList`
is not type-safe and requires casting, while `Array` provides better performance and type
safety.

You might also like