C#泛型学习(一)。
2016-03-22 22:32
453 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GenercityApplication { public class GenericList<T> { private Node head; private class Node { private Node next; private T data; public Node(T t) { next = null; data = t; } public Node Next { get { return next; } set { next = value; } } public T Data { get { return data; } set { data = value; } } } public GenericList() { head = null; } public void AddHead(T t) { Node n = new Node(t); n.Next = head; head = n; } public IEnumerator<T> GetEnumerator() { Node current = head; while (current != null) { yield return current.Data; current = current.Next; } } } class People { public int age; public string name; } class TestGenericList { static void Main() { GenericList<People> list = new GenericList<People>(); //for (int x = 0; x < 10; x++) { // list.AddHead(x); //} //foreach (int i in list) { // Console.WriteLine(i + ""); //} list.AddHead(new People()); Console.Read(); } } }
官网上的事例。
相关文章推荐
- (转)C#的 GC工作原理基础
- C#语言 数据类型 变量常量 数据转换 3.22
- C# 理解Thread.Sleep()
- C#解leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
- C#中string和byte[]相互转换问题解决
- c#多维数组
- C#中委托和Lambda表达式
- 文件
- C#如何调用其他.config配置文件,就是2个乃至3个以上的config文件
- C#机房重构——导出excel表
- ffmpeg从rtsp抓流存flv[c# NReco.VideoConverter flv]
- c# 学习之一:编码约定
- 登山-C#-为枚举创建新方法
- c# - StringTest
- 如何使用C#创建WebService
- C# Winform中窗体的美化——用IrisSkin4.dll美化你的WinForm
- c#输入一个字符串,并把字符串的第一个字符变为大写,如果字符串中有空格则把空格的下个字符变为大写之后输出
- C# WinForm实现Win7 Aero磨砂效果
- C#中Math.Round四舍五入的用法详解,
- 登山-C#-enum类型基础