Posted By

yesraaj on 10/25/10


Tagged

list generics Arbitarytypes


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


List of different type


 / Published in: C#
 

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Raj
  5. {
  6. namespace Generics
  7. {
  8. class Node
  9. {
  10. private Node next_;
  11.  
  12. public Node(Node next) {
  13. next_ = next;
  14. }
  15.  
  16. public Node getNext() {
  17. return next_;
  18. }
  19. }
  20. internal sealed class TypeList<T> :Node
  21. {
  22. T data_;
  23. public T getData() {
  24. return data_;
  25. }
  26.  
  27. public TypeList(T data, Node next):base(next) {
  28. data_ = data;
  29. }
  30.  
  31. public TypeList(T data):this(data,null) {
  32.  
  33.  
  34. }
  35. public override String ToString()
  36. {
  37. return data_.ToString() + (base.getNext() != null ? base.getNext().ToString() : string.Empty);
  38. }
  39.  
  40. //public override String ToString()
  41. //{
  42. // String temp;
  43. // if (base.getNext() != null)
  44. // {
  45. // temp = base.getNext().ToString();
  46. // }
  47. // else
  48. // {
  49. // temp = string.Empty;
  50. // }
  51. // return data_.ToString() + " " + temp;
  52. //}
  53. }
  54. class Dummmy:Object
  55. {
  56. public override String ToString() {
  57. return "Dummytype".ToString();
  58.  
  59. }
  60.  
  61. }
  62.  
  63. class Program
  64. {
  65. static void Main(string[] args)
  66. {
  67. Dummmy dummy = new Dummmy();
  68. Node list = new TypeList<int>(12);
  69. list = new TypeList<Double>(12.5121, list);
  70. list = new TypeList<Dummmy>(dummy, list);
  71. Double a = ((TypeList<Double>)list).getData();
  72. Console.WriteLine(list.ToString());
  73. Console.Write("sds");
  74. }
  75. }
  76. }
  77.  
  78. }

Report this snippet  

You need to login to post a comment.