C#数据结构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2079032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:19:48  来源:igfitidea点击:

C# data structures

c#

提问by nubela

I'm building an app in C#, however I'm new to the language though its pretty easy to learn because its too damn similar to Java.

我正在用 C# 构建一个应用程序,但是我是该语言的新手,尽管它很容易学习,因为它与 Java 太相似了。

However, I'm getting lost with the data structures as I haven't found a list of comprehensive available data structures with their methods like how Java has them.

但是,我对数据结构迷失了方向,因为我还没有找到完整的可用数据结构及其方法的列表,例如 Java 的方法。

Anyone has a reference list of available data structs for C# and their methods?

任何人都有 C# 及其方法的可用数据结构的参考列表?

采纳答案by Mehrdad Afshari

Most of the data structures you'll use in C# are contained in the System.Collections.Generic namespace. There are some rarely used data structures in the System.Collections.Specialized namespace. Also, there are some older, non-generic versions of data structures that are mostly deprecated since the introduction of generics in C# 2.0 available in the System.Collections namespace.

您将在 C# 中使用的大多数数据结构都包含在System.Collections.Generic 命名空间中System.Collections.Specialized 命名空间中有一些很少使用的数据结构。此外,自 C# 2.0 中System.Collections 命名空间中可用的泛型引入以来,有一些较旧的非泛型数据结构版本大多已被弃用。

Scott Mitchell has a nice introductory article set about some data structures in .NET: An Extensive Examination of Data Structures Using C# 2.0.

Scott Mitchell 有一篇很好的介绍性文章,介绍了 .NET 中的一些数据结构:使用 C# 2.0 对数据结构进行广泛检查

If you're coming from a Java background, you'll notice that unlike Java, .NET data structures are named after their function, not the way they are implemented.

如果您有 Java 背景,您会注意到与 Java 不同的是,.NET 数据结构以其功能命名,而不是以它们的实现方式命名。

回答by duffymo

Like the Java Collections, C# has a hierarchy of interfaces that includes collections (ICollection), lists (IList), and map (IDictionary) semantics. It maps 1:1 onto java.util.collections, with the exception of java.util.Set. There's no set in C# today. ISet is supposed to be on the way in .NET 4.0.

与 Java 集合一样,C# 有一个接口层次结构,其中包括集合 (ICollection)、列表 (IList) 和映射 (IDictionary) 语义。它将 1:1 映射到 java.util.collections 上,java.util.Set 除外。今天在 C# 中没有设置。ISet 应该会在 .NET 4.0 中出现。

回答by Tamas Czinege

You're going to love them. C# data structures combined with LINQ offer so much more than Java. Check out the System.Collections.Genericnamespace. One important note that almost any generic collection implements the IEnumerable<T>interface one way or other and you can LINQ to any IEnumerable<T> object:

你会爱上他们的。C# 数据结构与 LINQ 相结合提供了比 Java 多得多的功能。查看System.Collections.Generic命名空间。一个重要的注意事项,几乎所有泛型集合都以某种方式实现IEnumerable<T>接口,您可以 LINQ 到任何 IEnumerable<T> 对象:

List<SomeClass> yourList = new List<SomeClass>();
// Add elements ...
var redElementsOnly = yourList.Where(e => e.IsRed);

Check out the System.Linq.Enumerableclass for a complete list of what LINQ can do for you.

查看System.Linq.Enumerable类以获得 LINQ 可以为您做什么的完整列表。

回答by Paolo

You may find these MSDN pages useful: The C# Programming Language for Java Developers

您可能会发现这些 MSDN 页面很有用: Java 开发人员的 C# 编程语言