what are the most used interfaces in C#? [closed]
I tried searching for the most used built-in interfaces in C#, but couldn't find an article, so I thought we may recap here.
Let's use the following convention in the answers:
IinterfaceName1: for this
IinterfaceName2: for that
The top two in my mind have to be ones with language support:
IEnumerable<T>
(andIEnumerable
): for use withforeach
and LINQIDisposable
: for resources requiring cleanup, used withusing
Beyond that...
IComparable<T>
andIComparer<T>
: for generalized sortingIEquatable<T>
andIEqualityComparer<T>
: for generalized equalityIList<T>
andICollection<T>
: for mutable collectionsIDictionary<T,K>
: for lookup collections
INotifyPropertyChange
: For data binding to UI classes in WPF, winforms and silverlight
IQueryable<T>
: lets you execute requests against queriable data sources. For example
IQueryable<Project> projects = db.Projects;
var selectedItems = projects
.Where(x => x.Workers.Count() > 10 && x.Status != 1)
.ToArray();
In this example filtering would be done on SQL Server (in involves tricky mechanics with translating Expression x => x.Workers.Count() > 10 && x.Status != 1
to SQL statements)
So no need to write custom SQL commands to use all might of data source.
Also can be used not only with SQL, you can query objects or anything else, just find implementation of IQueryable<T>
精彩评论