开发者

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

开发者_如何学C As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.

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> (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


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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜