设为首页 加入收藏

TOP

C#中泛型的解释(object,list,var,dynamic的区别)(四)
2019-09-17 16:25:53 】 浏览:34
Tags:解释 object list var dynamic 区别
//
</summary> /// <param name="data"></param> public void Add(Object data) { if (headNode == null) { headNode = new Node<T>(data); } else { headNode.Append(new Node<T>(data)); } } /// <summary> /// 线性链表创建一个索引器。 /// </summary> /// <param name="index"></param> /// <returns></returns> public object this[int index] { get { int ctr = 0; Node<T> node = headNode; while (node != null && ctr <= index) { if (ctr == index) { return node.Data; } else { node = node.Next; } ctr++; } return null; } } /// <summary> /// 用以调用headNode的ToString()方法。 /// </summary> /// <returns></returns> public override string ToString() { if (this.headNode != null) { return this.headNode.ToString(); } else { return string.Empty; } } } } View Code
static void Main(string[] args)
        {
            /**泛型**/
            LinkedList<int> ll = new LinkedList<int>();
            for (int i = 0; i < 10; i++)
            {
                ll.Add(i);
            }

            Console.Write(ll);
            Console.WriteLine("  Done.");

            LinkedList<Employee> employees = new LinkedList<Employee>();
            employees.Add(new Employee("Jason1"));
            employees.Add(new Employee("Jason2"));
            employees.Add(new Employee("Jason3"));
            employees.Add(new Employee("Jason4"));

            Console.Write(employees);
            Console.WriteLine("  Done.");

            Console.WriteLine("The fourth integer is {0}.", ll[3]);

            Employee d = (Employee)employees[1];
            Console.WriteLine("The second Employee is {0}.", d);

            Console.ReadLine();
        }

 

其他的基础功能

1.  C#高级功能(四)扩展方法和索引

2. C#高级功能(三)Action、Func,Tuple

3. C#高级功能(二)LINQ 和Enumerable类

4. C#高级功能(一)Lambda 表达式

5. C#中泛型的解释(object,list,var,dynamic的区别)

6. C#中委托

7. C#和.NET版本对比

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#中委托 下一篇WCF入门

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目