1     internal class Node
 2     {
 3         protected Node m_next;
 4         public Node(Node next)
 5         {
 6             m_next = next;
 7         }
 8 
 9     }
10     internal class TypedNode<T> : Node
11     {
12         public T m_data;
13         public TypedNode(T data)
14             : this(data, null)
15         {
16 
17         }
18         public TypedNode(T data, Node next)
19             : base(next)
20         {
21             m_data = data;
22         }
23         public override string ToString()
24         {
25             return m_data.ToString() + ((m_next == null ? null : m_next.ToString()));
26         }
27     }

 

测试代码:

            Node head = new TypedNode<Char>('.');
            head = new TypedNode<DateTime>(DateTime.Now, head);
            head = new TypedNode<string>(" Today is ", head);
            Console.WriteLine(head.ToString());

 

Codes from <CLR via C# 3>

相关文章:

  • 2022-12-23
  • 2021-08-24
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-08-28
猜你喜欢
  • 2022-12-23
  • 2021-04-10
  • 2021-09-23
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案