如何在c#中创建泛型类。 [英] How to create generic class in c#.

查看:97
本文介绍了如何在c#中创建泛型类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请描述我如何在 c#中创建

Please describe me how to create

Generic class in c#.





我的尝试:



我试图在c#



What I have tried:

I have tried to create Generic class in c#

推荐答案

中创建Generic类我会开始阅读文档 [ ^ ]。
I would start reading the documentation[^].


通用编程概念不仅与C#编程有关。泛型已经用于许多其他语言,例如C ++和Java。问题是,他们也使用相同的符号表示泛型; 钻石符号



您可以创建自己的泛型,并在其中使用其他泛型类型,依此类推。只要您使用钻石符号并遵循一些关于它们的规则。你很高兴。

The generic programming concept is not just related to C# programming. Generics have been used in many other languages such as C++ and Java. The thing is, they used the same notation for generics too; Diamond notation.

You can create your own generics, and use other generic types in them and so on and so forth. As long as you're using the diamond notation and following a few rules about them. You're good to go.
public class Template<T> {
   // T is the Type for which, your template will work.
   private T data { get; set; }

   // Write functions to perform here
}



如前所述,您应该首先从文档中了解更多相关信息。甚至MSDN也必须将它们分发到3个不同的文档中(在相同的类别和指南下,但在不同的主题中),讨论它们并向初学者解释这个概念。



泛型简介(C#编程指南) [ ^ ]

通用类(C#编程指南) [ ^ ]

Generics(C#编程指南) [ ^ ]


As already suggested, you should start by learning more about them from the documentation. Even the MSDN had to distribute them in 3 different documentations (under the same category and guide, but in different theme), to talk about them and explain the concept to the beginners.

Introduction to Generics (C# Programming Guide)[^]
Generic Classes (C# Programming Guide)[^]
Generics (C# Programming Guide)[^]


希望以下链接有用。



C# - 泛型 [ ^ ]



C#转角:错误显示 [ ^ ] < br $> b $ b

http://www.dotnetperls.com/generic [< a href =http://www.dotnetperls.com/generictarget =_ blanktitle =New Window> ^ ]



泛型简介(C#编程指南) [ ^ ]
Hope these links below will help.

C# - Generics[^]

C# Corner : Error Display[^]

http://www.dotnetperls.com/generic[^]

Introduction to Generics (C# Programming Guide)[^]


这篇关于如何在c#中创建泛型类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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