A sample of Generics.
来源:互联网 发布:2015国产耽美网络剧 编辑:程序博客网 时间:2024/05/13 14:35
A Sample of Generics.
.net 2.0+C#+csc
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class TestGenerics<T>
...{
private T t;
public T TT...{ set...{ t=value;}
get...{return t;}}
}
public class Client
...{
public static void Main()
...{
Console.WriteLine("The value of T is {0}:", new TestGenerics<int>().TT=124);
}
}
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class TestGenerics<T>
...{
private T t;
public T TT...{ set...{ t=value;}
get...{return t;}}
}
public class Client
...{
public static void Main()
...{
Console.WriteLine("The value of T is {0}:", new TestGenerics<int>().TT=124);
}
}
编译运行。
在链表中使用范型。
using System;
public class Node<T>
...{
T value;
Node<T> next;
public Node(T value)
...{
this.value=value;
}
public T Value
...{
get
...{
return this.value;
}
set
...{
this.value=value;
}
}
public Node<T> Next
...{
get
...{
return next;
}
set
...{
next=value;
}
}
}
public class List<T>
...{
Node<T> root;
public List()
...{
root=null;
}
public void AddNode(T value)
...{
if(root==null)
root=new Node<T>(value);
else
...{ Node<T> newNode=new Node<T>(value);
Node<T> currentNode=root;
root=newNode;
newNode.Next=currentNode;}
}
public void TraverseList()
...{
Node<T> n=root;
while(n!=null)
...{
Console.WriteLine(n.Value.ToString());
n=n.Next;
}
}
public Node<T> Root
...{
get
...{
return root;
}
}
}
public class test
...{
public static void Main(string []args)
...{
List<int> l=new List<int>();
l.AddNode(10);
l.AddNode(11);
l.TraverseList();
List<string> ls=new List<string>();
ls.AddNode("a");
ls.AddNode("b");
ls.AddNode("c");
ls.AddNode("d");
ls.AddNode("e");
ls.AddNode("f");
ls.AddNode("g");
ls.TraverseList();
}
}
public class Node<T>
...{
T value;
Node<T> next;
public Node(T value)
...{
this.value=value;
}
public T Value
...{
get
...{
return this.value;
}
set
...{
this.value=value;
}
}
public Node<T> Next
...{
get
...{
return next;
}
set
...{
next=value;
}
}
}
public class List<T>
...{
Node<T> root;
public List()
...{
root=null;
}
public void AddNode(T value)
...{
if(root==null)
root=new Node<T>(value);
else
...{ Node<T> newNode=new Node<T>(value);
Node<T> currentNode=root;
root=newNode;
newNode.Next=currentNode;}
}
public void TraverseList()
...{
Node<T> n=root;
while(n!=null)
...{
Console.WriteLine(n.Value.ToString());
n=n.Next;
}
}
public Node<T> Root
...{
get
...{
return root;
}
}
}
public class test
...{
public static void Main(string []args)
...{
List<int> l=new List<int>();
l.AddNode(10);
l.AddNode(11);
l.TraverseList();
List<string> ls=new List<string>();
ls.AddNode("a");
ls.AddNode("b");
ls.AddNode("c");
ls.AddNode("d");
ls.AddNode("e");
ls.AddNode("f");
ls.AddNode("g");
ls.TraverseList();
}
}
编译运行。
- A sample of Generics.
- A sample of indexers.
- a sample of Interators
- a starting sample of paint
- a sample of delegate & event
- MoveBoxs, a sample of Bluetooth
- a sample of pc table
- A Basic Sample of jQuery Templates
- Arrays of generics
- A simple sample of Interactive Surface of Revolution
- A Sample Of HQL And It's Application
- Sample of C++ read/write a text file
- BAPI_SALESORDER_CHANGE a sample of bapi which reject sales orders
- [Code Sample]loop trough all records of a block
- [Code Sample]loop trough all blocks of a form
- Generics 通用型 a stack class
- GENERICS
- Generics
- Snd Reverser Tool 1.3, by Loki & PuNkDuDe
- 可以延年益寿的世界之最,您知多少?
- 对张孝祥C语言试题其中一题的探讨 (转载)
- table 行的显示与隐藏
- 设计模式之设计原则
- A sample of Generics.
- 有新家了,回IT行列了!
- MSNP9协议分析报告
- 你如何让Javascript和c直接互调?
- public, protected, private,
- 使用javascript操纵HTML元素的自定义属性
- Get-Acl 帮助信息
- 我站在中石油48元之巅
- 边缘的边缘程序员