What is C#? C# (pronounced “C sharp”) is a modern, general-purpose programming language developed by Microsoft. It is widely used for building a variety of applications on the .NET platform.
Who created C#? C# was created by Microsoft and led by Anders Hejlsberg, the chief architect of C#.
What are the main features of C#? C# features include strong typing, object-oriented programming (OOP), garbage collection, scalability, platform independence (with .NET framework), and extensive libraries.
What is the .NET framework? The .NET framework is a software framework developed by Microsoft that provides a runtime environment and a set of libraries for building applications in various languages, including C#.
What is the difference between C# and .NET? C# is a programming language, whereas .NET is a framework that includes the runtime, libraries, and tools for building applications. C# is one of the languages that can be used to develop applications on the .NET framework.
What is the difference between C# and C++? C# and C++ are both programming languages, but C# is a modern, managed language with automatic memory management (garbage collection) and is used primarily for application development. C++ is a low-level language that allows manual memory management and is often used for systems programming and performance-critical applications.
What is the difference between C# and Java? C# and Java are similar in many ways, as both are object-oriented languages. However, C# is primarily associated with the Microsoft ecosystem and is used with the .NET framework, while Java is platform-independent and is used with the Java Virtual Machine (JVM).
What is the difference between value types and reference types in C#? Value types store their actual values, whereas reference types store references to objects. Value types are allocated on the stack, while reference types are allocated on the heap.
What are the different data types in C#? C# provides several built-in data types, including integers, floating-point numbers, characters, booleans, strings, and more. It also allows the creation of user-defined custom data types.
What is boxing and unboxing in C#? Boxing is the process of converting a value type to an object type, and unboxing is the reverse process of extracting the value from an object type back to a value type.
What is the difference between struct and class in C#? Structs are value types and are stored on the stack, while classes are reference types and are stored on the heap. Structs have value semantics, while classes have reference semantics.
What is the difference between public, private, and protected access modifiers? public allows access from anywhere, private restricts access to within the same class, and protected allows access within the same class and derived classes.
What is the difference between override and new keywords in C#? The override keyword is used to override a virtual or abstract method in a derived class, while the new keyword is used to hide an inherited member and provide a new implementation.
What is the difference between const and readonly fields in C#? A const field is a compile-time constant and its value cannot be changed. A readonly field can be assigned a value either at declaration or in the constructor, and its value can only be changed in the constructor.
What is the difference between sealed and static modifiers in C#? The sealed modifier is used to prevent inheritance of a class or override of a method, while the static modifier is used to create members that belong to the type itself rather than to an instance of the type.
What is the purpose of the using statement in C#? The using statement is used for automatic disposal of resources. It ensures that the Dispose method of an object is called, even if an exception occurs.
What are delegates in C#? Delegates are type-safe function pointers that allow methods to be passed as parameters or stored as variables. They are used for event handling and callback mechanisms.
What are events in C#? Events are a mechanism in C# that allow objects to communicate with each other. They enable the publishing and subscribing of notifications when a specific action or state change occurs.
What is LINQ in C#? LINQ (Language-Integrated Query) is a set of language extensions in C# that provides a unified syntax to query and manipulate data from different sources, such as collections, databases, and XML.
What are properties in C#? Properties in C# provide a way to encapsulate fields and provide controlled access to them. They allow the use of getters and setters to read and write values, while providing additional logic if needed.
What are indexers in C#? Indexers are special properties that allow objects to be indexed like arrays. They provide a way to access elements of a class or struct using square bracket notation.
What is serialization in C#? Serialization is the process of converting an object into a stream of bytes to store it or transmit it over a network. Deserialization is the reverse process of reconstructing the object from the serialized bytes.
What is asynchronous programming in C#? Asynchronous programming in C# allows the execution of tasks concurrently, without blocking the main thread. It improves the responsiveness and scalability of applications.
What are async and await keywords in C#? The async and await keywords are used in asynchronous programming to mark methods as asynchronous and to wait for the completion of an asynchronous operation respectively.
What are extension methods in C#? Extension methods allow adding new methods to existing types without modifying their original source code. They are used to provide additional functionality to classes, interfaces, or structs.
What is the difference between an interface and an abstract class in C#? An interface defines a contract for a set of methods and properties that a class must implement, while an abstract class can provide a partial implementation and can be inherited by derived classes.
What is the difference between a shallow copy and a deep copy in C#? A shallow copy creates a new object and copies the references of the original object’s fields, while a deep copy creates a new object and recursively copies the values of the original object’s fields.
What is the purpose of the StringBuilder class in C#? The StringBuilder class is used for efficient string manipulation. It provides methods to append, replace, insert, and manipulate strings without creating multiple intermediate string objects.
What is the purpose of the try-catch-finally block in C#? The try-catch-finally block is used for exception handling in C#. The try block contains the code that may throw an exception, the catch block handles the exception, and the finally block is executed regardless of whether an exception occurs or not.
What is the purpose of the using directive in C#? The using directive is used to include namespaces in a C# file. It allows accessing types and members of those namespaces without fully qualifying their names.
What is the purpose of the Nullable struct in C#? The Nullable struct allows value types to have a null value. It provides a way to represent the absence of a value for value types like int, bool, etc.
What are attributes in C#? Attributes provide a way to add metadata or declarative information to types and their members. They can be used for various purposes such as code generation, documentation, and runtime behavior modification.
What is reflection in C#? Reflection is a feature in C# that allows programmatic access to type information at runtime. It enables querying and manipulating types, methods, properties, and other members dynamically.
What are generics in C#? Generics allow the creation of reusable code that can work with different types without sacrificing type safety. They enable the creation of type-parameterized classes, interfaces, and methods.
What is the purpose of the lock keyword in C#? The lock keyword is used to create mutually exclusive blocks of code or methods. It ensures that only one thread can access the locked code at a time, preventing data inconsistency in multithreaded scenarios.
What are anonymous methods in C#? Anonymous methods are unnamed methods that can be used as delegates. They provide a concise way to define and use inline methods without explicitly declaring a separate named method.
What are lambda expressions in C#? Lambda expressions are anonymous functions that can be used to create delegates or expression trees. They provide a concise syntax for writing inline code blocks.
What is the difference between IEnumerable and IEnumerator in C#? IEnumerable represents a collection that can be enumerated, while IEnumerator provides a way to iterate over the elements of an IEnumerable collection.
What is the difference between as and is keywords in C#? The as keyword is used for safe type casting, where if the cast fails, it returns null instead of throwing an exception. The is keyword is used for type checking, where it returns a boolean value indicating whether a variable is of a specific type.
What is the purpose of the yield keyword in C#? The yield keyword is used in iterator methods to simplify the implementation of custom iterators. It allows the method to return a sequence of values without blocking the calling code.
What is the purpose of the var keyword in C#? The var keyword allows implicit type inference during variable declaration. The compiler determines the type of the variable based on the assigned value.
What is the purpose of the nameof operator in C#? The nameof operator is used to obtain the name of a variable, type, or member as a string. It provides a way to refer to the names in a type-safe manner, avoiding hard-coded strings.
What is the purpose of the async modifier in C#? The async modifier is used to mark a method as asynchronous. It allows the method to use the await keyword and enables the method to be executed asynchronously without blocking the calling thread.
What is the purpose of the await keyword in C#? The await keyword is used in asynchronous methods to indicate a point where the method can asynchronously wait for the completion of an awaited task before proceeding further.
What is the difference between a value task and a task in C#? A Task represents a potentially asynchronous operation that returns a result, while a ValueTask represents a potentially asynchronous operation that returns a value. ValueTask is used for optimizing small, short-lived asynchronous operations to avoid unnecessary allocations.
What is the purpose of the Task Parallel Library (TPL) in C#? The Task Parallel Library (TPL) is a set of types and APIs in C# that simplifies the process of writing parallel and asynchronous code. It provides abstractions for parallelism, task-based asynchronous programming, and data parallelism.
What is the purpose of the PLINQ in C#? PLINQ (Parallel LINQ) is an extension of LINQ that enables writing queries that can be executed in parallel across multiple threads. It allows efficient processing of large data sets by utilizing the power of multiple processors or cores.
What is the purpose of the async/await pattern in C#? The async/await pattern in C# simplifies asynchronous programming by providing a more readable and structured way to write asynchronous code. It allows developers to write code that looks synchronous but executes asynchronously.
What is the purpose of the Task.Run method in C#? The Task.Run method is used to queue a delegate for execution on a thread pool thread. It provides a convenient way to execute code asynchronously and in parallel.