很好的泛型介绍

发布于 2024-08-11 21:38:43 字数 122 浏览 4 评论 0原文

受到这些优势的驱使,我正在寻找一种将泛型编程集成到我当前的编程风格中的方法。我想在 C# 中使用泛型,但找不到任何好的介绍材料和一些日常使用示例。如果您有使用仿制药的经验:您认为哪些资源对学习仿制药最有用? (书籍、文章等...)

Being compelled by the advantages I'm looking for a way to integrate generic programming into my current programming style. I would like to use generics in C# but can't find any good introductory material with some everyday examples of use. If you have experience with generics: what resources did you find most useful learning them? (books, articles, etc...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

难以启齿的温柔 2024-08-18 21:38:43

O'reilly 关于仿制药的文章

我真的很喜欢Jon Skeet 所著的 C# in Depth 书中的泛型部分,虽然它不是介绍性的,但更......深入(就像当你熟悉泛型时阅读它,了解很多关于它们的有趣的事情,但不是作为一个介绍)。

O'reilly article on generics

And I really enjoyed the generics part of the C# in Depth book by Jon Skeet, although it's not introductory but more ... in depth (as in read it when you're comfortable with generics to know a lot of interesting things about them, but not as an introduction).

墨洒年华 2024-08-18 21:38:43

老实说,我发现仅使用 System.Collections.Generic 类是最好的起点。如果您还没有这样做,请从使用 System.Collections 类切换到新的通用变体。这会让你习惯这些概念。强类型字典是一件可爱的事情。

之后,创建您自己的泛型类就没有太大的概念飞跃了。 Intellisense 是一个很棒的指南。只需开始编写:

class Something<T> {
   T Item { get; set; }
}

并注意您的第二个“T”出现在智能感知中。 Visual Studio 正在为您加油!嘿,这很容易!

最终你会用尽显而易见的资源,然后需要更好的资源。迄今为止,Google 和 MSDN 已经是我所需要的一切,但是当您超越这些并想要更深入地了解时,您已经知道了足够的知识,可以找到适合您理解水平的最佳书籍。

祝你好运!

Honestly, I found just using the System.Collections.Generic classes to be the best starting point. If you aren't already, switch away from using the System.Collections classes to the new generic variants. That will get you used to the concepts. A strongly typed dictionary is a lovely thing.

After that it's not too much of a conceptual leap to create your own generic class. Intellisense is an amazing guide. Just start writing:

class Something<T> {
   T Item { get; set; }
}

And notice that your second "T" shows up in intellisense. Visual Studio is cheering you on! Hey, this is easy!

Eventually you'll exhaust the obvious and then will need a better resource. Google and MSDN has been all I've needed to date, but by the time you get beyond that and want a deeper understanding you'll already know enough to find the best books for your level of understanding.

Good luck!

以歌曲疗慰 2024-08-18 21:38:43

如果您要使用 C# 和 .NET,我建议您查看 官方文档,特别是泛型编程指南简介

如果您已经了解 C#,但只想温习一下泛型,那么这些指南应该适合您。书中还给出了许多日常代码示例。

If you're going to be using C# and .NET, I'd recommend you go over the official docs, specifically, the Introduction to Generics Programming Guide.

These guides should be at the right level for you if you already know C#, but just want to brush up on generics. Lots of day-to-day code examples are also given throughout.

梦过后 2024-08-18 21:38:43

我写了两篇关于泛型的短文(主要针对 List 类)

http://dotnetchris.wordpress。 com/?s=泛型

I wrote 2 short articles about generics (mostly geared towards the List class)

http://dotnetchris.wordpress.com/?s=generics

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文