what are the most used interfaces in C#? [closed]

懵懂的女人 提交于 2020-01-01 08:06:16

问题


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


回答1:


The top two in my mind have to be ones with language support:

  • IEnumerable<T> (and IEnumerable): for use with foreach and LINQ
  • IDisposable: for resources requiring cleanup, used with using

Beyond that...

  • IComparable<T> and IComparer<T>: for generalized sorting
  • IEquatable<T> and IEqualityComparer<T>: for generalized equality
  • IList<T> and ICollection<T>: for mutable collections
  • IDictionary<T,K>: for lookup collections



回答2:


INotifyPropertyChange : For data binding to UI classes in WPF, winforms and silverlight




回答3:


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>



来源:https://stackoverflow.com/questions/4240438/what-are-the-most-used-interfaces-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!