首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏葡萄城控件技术团队

    最全数据结构详述: List VS IEnumerable VS IQueryable VS ICollection VS IDictionary

    本文对常用的数据结构详述:Array, ArrayList,List,IList,ICollection, Stack, Queue, HashTable, Dictionary, IQueryable ICollection 继承了IEnumberable,但是IEnumberable是基于索引的,ICollection不基于索引。 ? 1: //IList {indexer and Modify} vs ICollection {randomly and Modify} 2: //Collection can not be instantiate from ICollection , so it should be instantiate from List 3: System.Collections.Generic.ICollection *** 29: System.Collections.Generic.ICollection<Employee> objICollection = new List<Employee>();

    2.3K80发布于 2018-01-10
  • 来自专栏walterlv - 吕毅的博客

    为什么实现 .NET 的 ICollection 集合时需要实现 SyncRoot 属性?如何正确实现这个属性?

    非泛型版本的 ICollection 中有 IsSynchronized 属性和 SyncRoot 属性,这两个属性被用来设计成以线程安全的方式访问和修改集合。 虽然泛型版本的 ICollection<T> 已经改进了设计,不再引入 SyncRoot 这样的属性到接口中,但如果我们在某些场景下需要实现 ICollection 非泛型集合时,如何正确实现 SyncRoot 而 ICollection 接口中的 SyncRoot 属性在接口中必然是公开的,于是没有任何途径可以保证调用方不会发生死锁。 bool ICollection.IsSynchronized => false; // Synchronization root for this object. object ICollection.SyncRoot

    1.2K30发布于 2020-01-08
  • 来自专栏跟着阿笨一起玩NET

    自定义Dictionary支持线程安全

    (key); } ///

    /// Gets an <see cref="T:System.Collections.Generic.<em>ICollection</em> summary> /// <value></value> /// <returns>An <see cref="T:System.Collections.Generic.ICollection </returns> public ICollection<TKey> Keys { get { </returns> public ICollection<TValue> Values { get { -or-The number of elements in the source <see cref="T:System.Collections.Generic.<em>ICollection</em>`1"></see

    1.2K10发布于 2018-09-19
  • 来自专栏c#开发者

    DataAnnotations - InverseProperty Attribute:

    public int StandardId { get; set; } public string StandardName { get; set; } public ICollection <Student> CurrentStudents { get; set; } public ICollection<Student> PreviousStudents { get; set; public string StandardName { get; set; } [InverseProperty("CurrentStandard")] public ICollection public string StandardName { get; set; } [InverseProperty("CurrentStandard")] public ICollection Student> CurrentStudents { get; set; } [InverseProperty("PreviousStandard")] public ICollection

    944120发布于 2018-04-12
  • 来自专栏全栈程序员必看

    C#语言各种集合介绍

    4)IDictionary IDictionary实现是键/值对的集合,它本身实现了ICollection和IEnumerable接口 是键/值对的集合的基接口。 3)Hashtable 实现了接口:IDictionary、ICollection、IEnumerable 可以向Hashtable中自由添加和删除元素,有些像ArrayList,但没有那么大的性能开销 4)SortedList 实现了接口:IDictionary、ICollection、IEnumerable SortedLIst兼顾了ArrayList和Hashtable的优点,可按键值来排序 5 )Queue 实现了接口:ICollection、IEnumerable Queque是队列,先进先出的访问各个元素 可以调用Queque对象的GetEnumerator()方法,得到IEnumerator 对象,来遍历队列中的各个元素 6)Stack 实现了接口:ICollection、IEnumerable Stack是堆栈,后进先出的访问各个元素 可以调用Stack对象的GetEnumerator()

    1K21编辑于 2022-07-15
  • 来自专栏张善友的专栏

    编写前置和后置条件的连贯接口库:CuttingEdge.Conditions

    下面是一个用CuttingEdge.Conditions的例子: public ICollection GetData(Nullable<int> id, string xml, ICollection Check all postconditions:     Condition.Ensures(result, "result")         .IsOfType(typeof(ICollection )); // throws PostconditionException on failure     return (ICollection)result; } public static

    68170发布于 2018-01-19
  • 来自专栏centosDai

    CA1710:标识符应具有正确的后缀

    基类型/接口 Suffix System.Attribute 属性 System.EventArgs EventArgs System.Exception 例外 System.Collections.ICollection TValue> 字典 System.Collections.Queue 集合或队列 System.Collections.Stack 集合或堆栈 System.Collections.Generic.ICollection EventHandler 实现 ICollection 的类型是一种通用的数据结构类型(如字典、堆栈或队列),允许在名称中包含有关该类型预期用途的有用信息。 实现 ICollection 的类型是特定项的集合,其名称以单词 Collection 结尾。 例如,Queue 对象的集合的名称会是 QueueCollection。 这些集合通过 System.Data.InternalDataCollectionBase 基类实现 ICollection。 如何解决冲突 重命名该类型,使其带有正确的字词后缀。

    2500编辑于 2022-02-25
  • 来自专栏张善友的专栏

    ADO.NET实体框架连接串引发的异常:Unable to load the specified metadata resource

    System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection

    1.6K60发布于 2018-01-19
  • 来自专栏喵叔's 专栏

    通过运行期类型检查实现泛型算法

    一、第二次优化 上述代码基本上囊括了大部分情况,但有时我们还会遇到一些集合只实现了 ICollection 而没有实现 IList 的情况,这种情况下我们代码中的 GetEnumerator 方法性能就不是很高了 public IEnumerator<T> GetEnumerator() { if(orgSequence == null) { if(orgSequence is ICollection <T>) { ICollection<T> src = orgSequence as ICollection<T>; orgSequence DemoStringEnumerator(sreSequence as string); } if(orgSequence == null) { if(orgSequence is ICollection <T>) { ICollection<T> src = orgSequence as ICollection<T>; orgSequence

    88110发布于 2020-09-08
  • 来自专栏stcnb

    CA1010:集合应实现泛型接口

    如何解决冲突 若要解决此规则的冲突,请实现某个泛型集合接口: System.Collections.Generic.IEnumerable<T> System.Collections.Generic.ICollection 通过接口实现来解决 以下示例通过实现 IEnumerable<T>、ICollection<T> 和 IList<T> 等泛型接口来解决冲突。 <Book>.Add(Book item) { } bool ICollection<Book>.Contains(Book item) { return true; } void ICollection<Book>.CopyTo(Book[] array, int arrayIndex) { } bool ICollection <Book>.IsReadOnly { get { return false; } } bool ICollection<Book>.Remove(Book item

    87850编辑于 2022-01-10
  • 来自专栏全栈程序员必看

    用C#编程的建议建议收藏

    如果你用ICollection接口来写那段程序,你就不用修改那段程序了,对于任何实现ICollection接口的类型它都能很好的工作: 1 private void LoadList (ICollection ListBox l) 2 { 3   foreach (object o in items) 4   l.Items.Add (o.ToString ()); 5 }   ICollection 此外,多维数组也支持ICollection接口。如果那还不够的话,数据库.NET类同样支持ICollection接口。用接口写的这个函数不用需改就可以才许多中情况下使用。 2.

    44420编辑于 2022-07-15
  • 来自专栏GreenLeaves

    分析模式一

    public class Department { public string DepartmentName { get; set; } public ICollection public class Role { public string RoleName { get; set; } public ICollection <User> Users { get; set; } public ICollection<Action> Actions { get; set; } } /// < class Department: IDepartment { public string DepartmentName { get; set; } public ICollection class Department: IDepartment { public string DepartmentName { get; set; } public ICollection

    30020编辑于 2022-03-24
  • 来自专栏技术/开源

    .net源码分析 – List<T>

    ICollection是集合接口,支持着集合的Count属性和CopyTo操作,另外还有同步的属性IsSynchronized(判断是否线程安全)和SyncRoot(lock的对象)。 泛型部分基本是上面这些接口的泛型实现,不过IList<T>的一些操作放到ICollection<T>里了,可能微软也觉得对于集合的一些操作放到ICollection更合理吧。 <T> c = collection as ICollection<T>; 8 if (c ! 如果不是ICollection,不过由于是IEnumerable,所以可以遍历,一个一个加到_items里。 属性 Count 返回的是_size,这个是元素的实际个数,不是数组大小。 1 Object System.Collections.ICollection.SyncRoot 2 { 3 get 4 { 5 if (_syncRoot ==

    95880发布于 2018-01-04
  • 来自专栏stcnb

    CA1829:使用 Length/Count 属性,而不是 Enumerable.Count 方法

    System.Collections.Immutable.ImmutableArray<T> 此规则标记具有 Count 属性的以下集合类型上的 Count 调用: System.Collections.ICollection System.Collections.Generic.ICollection<T> System.Collections.Generic.IReadOnlyCollection<T> 分析后的集合类型可能会在将来扩展 System.Linq; class C { public int GetCount(int[] array) => array.Count(); public int GetCount(ICollection System.Collections.Generic; class C { public int GetCount(int[] array) => array.Length; public int GetCount(ICollection

    78400编辑于 2022-02-19
  • 来自专栏Niuery的技术日记

    小工具 --- 树形展示多属性复杂结构类

    Name; arr[2] = "> "; } // 判断泛型类型是否为 ICollection <T> else if (typeDefinition == typeof(ICollection<>)) { arr[0] = "ICollection<"; arr[1] = typeArgs[0].Name; arr

    31130编辑于 2023-10-22
  • 来自专栏Dotnet9

    如何处理EF Core的多对多关系?

    public class Cart { public int Id { get; set; } public ICollection<Item> Items { get; set; } get; set; } public string Name { get; set; } public int Quantity { get; set; } public ICollection 您会得到以下结果: Unable to determine the relationship represented by navigation property ‘Cart.Items’ of type ‘ICollection 【无法确定类型为“ICollection<Item>”的导航属性“Cart.Items”表示的关系。 get; set; } public string Name { get; set; } public int Quantity { get; set; } public ICollection

    4.2K20发布于 2021-12-01
  • 来自专栏jessetalks

    C#集合类型大盘点

    俗话说知其然,知其所以然,平常看到IEnumerable,IEnumerator,ICollection是不是知道他们之间各自的区别?除了List和Dictionary以外,你还用过哪些其它的集合类? <T>和ICollection   从最上面第一张图我们可以知道,ICollection是直接继承自IEnumerable。 ICollectionICollection<T> 略有不同,ICollection不提供编辑集合的功能,即Add和Remove。包括检查元素是否存在Contains也不支持。 IList<T>和IList   IList则是直接继承自ICollection和IEnumerable。所以它包括两者的功能,并且支持根据下标访问和添加元素。 而ICollection支持的功能稍微多一点,不仅有遍历还有维护这个集合的功能。而IList是最全的版本。

    1.5K70发布于 2018-03-14
  • 来自专栏喵叔's 专栏

    EF Core如何处理多对多关系

    public class ShoppingCart { public int Id { get; set; } public ICollection<Commodity> Commoditys { get; set; } public string Name { get; set; } public int Quantity { get; set; } public ICollection to determine the relationship represented by navigation property 'ShoppingCart.Commoditys' of type 'ICollection ShoppingCart和Commodity的导航属性: public class ShoppingCart { public int Id { get; set; } public ICollection { get; set; } public string Name { get; set; } public int Quantity { get; set; } public ICollection

    2.8K30发布于 2021-11-24
  • 来自专栏centosDai

    CA1710:标识符应具有正确的后缀

    基类型/接口 Suffix System.Attribute 属性 System.EventArgs EventArgs System.Exception 例外 System.Collections.ICollection TValue> 字典 System.Collections.Queue 集合或队列 System.Collections.Stack 集合或堆栈 System.Collections.Generic.ICollection EventHandler 实现 ICollection 的类型是一种通用的数据结构类型(如字典、堆栈或队列),允许在名称中包含有关该类型预期用途的有用信息。 实现 ICollection 的类型是特定项的集合,其名称以单词 Collection 结尾。 例如,Queue 对象的集合的名称会是 QueueCollection。 这些集合通过 System.Data.InternalDataCollectionBase 基类实现 ICollection。 如何解决冲突 重命名该类型,使其带有正确的字词后缀。

    3300编辑于 2022-02-23
  • 来自专栏centosDai

    CA1710:标识符应具有正确的后缀

    基类型/接口 Suffix System.Attribute 属性 System.EventArgs EventArgs System.Exception 例外 System.Collections.ICollection TValue> 字典 System.Collections.Queue 集合或队列 System.Collections.Stack 集合或堆栈 System.Collections.Generic.ICollection EventHandler 实现 ICollection 的类型是一种通用的数据结构类型(如字典、堆栈或队列),允许在名称中包含有关该类型预期用途的有用信息。 实现 ICollection 的类型是特定项的集合,其名称以单词 Collection 结尾。 例如,Queue 对象的集合的名称会是 QueueCollection。 这些集合通过 System.Data.InternalDataCollectionBase 基类实现 ICollection。 如何解决冲突 重命名该类型,使其带有正确的字词后缀。

    1.3K00编辑于 2022-02-18
领券