IQueryable、ICollection、IList & 之间的区别IDictionary 接口 [英] Difference between IQueryable, ICollection, IList & IDictionary interface

查看:20
本文介绍了IQueryable、ICollection、IList & 之间的区别IDictionary 接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 IQueryable、ICollection、IList 和 & 之间的区别IDictionary 接口这对于迭代、索引、查询等基本操作来说更快.

I am trying to understand difference between IQueryable, ICollection, IList & IDictionary interface which is more faster for basic operations like iterating, Indexing, Querying and more.

哪些类(如 Collection、List、Dictionary 等)适合使用这些接口进行初始化,以及我们应该何时使用这些类.与其他类相比,使用这些类的基本优势.

which class like Collection, List, Dictionary etc would be good to initiating with these interfaces and when should we be using these class. Basic advantages of using these classes over others.

我尝试阅读其他有类似问题的帖子,但没有回答我的全部问题.感谢您的帮助.

I tried reading other posts with similar questions but nothing answered my full questions. Thanks for the help.

推荐答案

所有这些接口都继承自 IEnumerable,你应该确保你理解它.该接口基本上允许您在 foreach 语句(在 C# 中)中使用该类.

All of these interfaces inherit from IEnumerable, which you should make sure you understand. That interface basically lets you use the class in a foreach statement (in C#).

  • ICollection 是您列出的最基本的接口.这是一个支持 Count 的可枚举接口,仅此而已.
  • IList是ICollection的一切,但它也支持添加和删除项目,通过索引检索项目等.它是对象列表"最常用的接口,含糊不清我知道.
  • IQueryable 是一个支持 LINQ 的可枚举接口.您始终可以从 IList 创建 IQueryable 并使用 LINQ to Objects,但您也会发现 IQueryable 用于延迟执行 LINQ to SQL 和 LINQ to Entities 中的 SQL 语句.
  • IDictionary 是一种不同的动物,因为它是唯一键到值的映射.它也是可枚举的,因为您可以枚举键/值对,但除此之外,它的用途与您列出的其他用途不同.
  • ICollection is the most basic of the interfaces you listed. It's an enumerable interface that supports a Count and that's about it.
  • IList is everything that ICollection is, but it also supports adding and removing items, retrieving items by index, etc. It's the most commonly-used interface for "lists of objects", which is vague I know.
  • IQueryable is an enumerable interface that supports LINQ. You can always create an IQueryable from an IList and use LINQ to Objects, but you also find IQueryable used for deferred execution of SQL statements in LINQ to SQL and LINQ to Entities.
  • IDictionary is a different animal in the sense that it is a mapping of unique keys to values. It is also enumerable in that you can enumerate the key/value pairs, but otherwise it serves a different purpose than the others you listed.

其中每一个的 MSDN 文档都不错,所以我会从那里开始完善您的理解.

The MSDN documentation for each of these is decent, so I would start there in rounding out your understanding.

这篇关于IQueryable、ICollection、IList & 之间的区别IDictionary 接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆