In C#, there are several common interfaces that are widely used for different purposes. Here is a list of some of the most commonly used interfaces in C#:
- IEnumerable: Represents a collection that can be enumerated. It is used for iterating over a collection of items.
- IEnumerator: Provides methods for iterating over a collection. It is often used in conjunction with
IEnumerable
. - IComparable: Defines a method to compare one object with another object of the same type. Used for custom object comparisons.
- IEquatable: Defines a method to determine whether the current object is equal to another object of the same type. Used for custom object equality comparisons.
- IDisposable: Provides a mechanism for releasing unmanaged resources. It’s used for resource management and cleanup.
- IList: Represents a non-generic collection of objects that can be individually accessed by index. Common implementations include
List<T>
andArrayList
. - ICollection: Defines methods to manipulate generic collections. Common implementations include
List<T>
. - IDictionary: Represents a collection of key-value pairs. Common implementations include
Dictionary<TKey, TValue>
. - INotifyPropertyChanged: Used in data binding scenarios to notify clients when a property value changes.
- INotifyCollectionChanged: Used in data binding scenarios to notify clients when a collection changes, such as items being added or removed.
- IQueryable: Represents a queryable data source. It’s used in LINQ (Language Integrated Query) for querying collections and databases.
- IQueryable: A generic version of
IQueryable
, used for strongly-typed queries in LINQ. - ISerializable: Used for custom serialization of objects. Allows objects to control how they are serialized and deserialized.
- IAsyncResult: Represents the status of an asynchronous operation.
- IFormattable: Provides a way to format the value of an object into a string representation using a specified format.
- ICloneable: Defines a method to create a shallow copy of an object. It’s used for creating copies of objects.
- IConvertible: Provides methods for converting an object to different data types. It’s used for type conversion.
- IComparable: A generic version of
IComparable
, used for comparing objects of a specific type. - IEquatable: A generic version of
IEquatable
, used for determining equality of objects of a specific type. - IAsyncEnumerable: Introduced in C# 8.0, it represents an asynchronous stream of data.