Interview Questions C# Part 1

Basic C#
1. What is C#?
C# is a modern, object-oriented programming language developed by Microsoft as part of its .NET initiative. It is designed for building a variety of applications that run on the .NET Framework. C# is simple, powerful, type-safe, and object-oriented.
2. Explain the difference between value types and reference types in C#.
Value Types: These types hold their data directly. Examples include int, float, char, and struct. When you assign a value type variable to another, a copy of the value is made.
Reference Types: These types store references to their data (objects). Examples include class, interface, array, and delegate. When you assign a reference type variable to another, both variables refer to the same object.
3. What is the .NET Framework?
The .NET Framework is a software development platform developed by Microsoft. It provides a comprehensive and consistent programming model for building applications with visually stunning user experiences and seamless and secure communication. The .NET Framework includes a large class library named Framework Class Library (FCL) and provides language interoperability across several programming languages.
4. What is inheritance?
Inheritance is an OOP principle where a new class (derived class) inherits the properties and behavior (methods) of an existing class (base class). This allows for code reusability and establishes a natural hierarchy between classes. In C#, inheritance is implemented using the : symbol.
5. What is the difference between an abstract class and an interface?
Abstract Class: Can contain both abstract methods (without implementation) and concrete methods (with implementation). Abstract classes can have fields, constructors, and destructors. A class can inherit from only one abstract class.
Interface: Can only contain method signatures (declarations without implementation), properties, events, and indexers. Interfaces cannot have fields, constructors, or destructors. A class can implement multiple interfaces.
6. What is LINQ?
LINQ (Language Integrated Query) is a set of features in C# that provides query capabilities directly in the C# language. It allows you to query collections, databases, XML, and more using a consistent syntax similar to SQL.
7. Explain the concept of properties in C#.
Properties in C# are members that provide a flexible mechanism to read, write, or compute the values of private fields. They are defined using get and set accessors. Properties promote encapsulation by allowing access to class data in a controlled way.
public class Person
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
8. What is the difference between Task and Thread?
Thread: A thread is a lower-level construct used to create and manage threads directly. Threads are often more complex to handle due to the need for manual management of synchronization and state.
Task: A task is a higher-level construct that represents an asynchronous operation. It is part of the Task Parallel Library (TPL) and provides a simpler way to work with asynchronous code. Tasks can be automatically managed by the .NET runtime and are easier to use with async and await keywords.
9. What is the difference between Func, Action, and Predicate delegates?
Func: Represents a delegate that points to a method returning a value and having one or more parameters. Func<T, TResult> can have 0 to 16 input parameters.
Action: Represents a delegate that points to a method that does not return a value (void) and can have one or more parameters. Action<T> can have 0 to 16 input parameters.
Predicate: Represents a delegate that points to a method returning a boolean value and having one parameter. It is used to define a set of criteria and determine if the object meets those criteria.
10. What is the Common Language Runtime (CLR)?
The Common Language Runtime (CLR) is the execution engine for .NET applications. It provides key services such as memory management, garbage collection, exception handling, and security. The CLR allows applications written in different .NET languages (like C#, VB.NET, and F#) to execute and interact with each other, ensuring language interoperability and a consistent runtime environment.

No comments:
Post a Comment
Leave a comment