简体   繁体   中英

C# data structures

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.

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.

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

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 .

Scott Mitchell has a nice introductory article set about some data structures in .NET: An Extensive Examination of Data Structures Using 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.

You're going to love them. C# data structures combined with LINQ offer so much more than Java. Check out the System.Collections.Generic namespace. 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:

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM