code_junkie

What's the best way of using a pair (triple, etc) of values as one value in C#?

Nov 11th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. Dictionary<Pair<string, int>, object>
  2.  
  3. Dictionary<Triple<string, int, int>, object>
  4.  
  5. int id = 33;
  6. string description = "This is a custom solution";
  7. DateTime created = DateTime.Now;
  8.  
  9. KeyValuePair<int, KeyValuePair<string, DateTime>> triple =
  10. new KeyValuePair<int, KeyValuePair<string, DateTime>>();
  11. triple.Key = id;
  12. triple.Value.Key = description;
  13. triple.Value.Value = created;
  14.  
  15. KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string> quadruple =
  16. new KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string>();
  17. KeyValuePair<KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string>, string> quintuple =
  18. new KeyValuePair<KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string>, string>, string>();
  19.  
  20. struct Pair<T, R>
  21. {
  22. private T first_;
  23. private R second_;
  24.  
  25. public T First
  26. {
  27. get { return first_; }
  28. set { first_ = value; }
  29. }
  30.  
  31. public R Second
  32. {
  33. get { return second_; }
  34. set { second_ = value; }
  35. }
  36. }
  37.  
  38. public struct Pair<T1, T2>
  39. {
  40. public T1 First;
  41. public T2 Second;
  42. }
  43.  
  44. public struct Triple<T1, T2, T3>
  45. {
  46. public T1 First;
  47. public T2 Second;
  48. public T3 Third;
  49. }
  50.  
  51. int id = 33;
  52. string description = "This is a custom solution";
  53. DateTime created = DateTime.Now;
  54.  
  55. KeyValuePair<int, KeyValuePair<string, DateTime>> triple =
  56. new KeyValuePair<int, KeyValuePair<string, DateTime>>();
  57. triple.Key = id;
  58. triple.Value.Key = description;
  59. triple.Value.Value = created;
  60.  
  61. KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string, string> quadruple =
  62. new KeyValuePair<KeyValuePair<KeyValuePair<string, string>, string, string>();
  63.  
  64. public Tuple<int, string, int> GetSomething()
  65. {
  66. //do stuff to get your multi-value return
  67. }
  68.  
  69. //then call it:
  70. var retVal = GetSomething();
  71.  
  72. //problem is what does this mean?
  73. retVal.Item1 / retVal.Item3;
  74. //what are item 1 and 3?
  75.  
  76. class CustomRetVal {
  77. int CurrentIndex { get; set; }
  78. string Message { get; set; }
  79. int CurrentTotal { get; set; }
  80. }
  81.  
  82. var retVal = GetSomething();
  83.  
  84. //get % progress
  85. retVal.CurrentIndex / retVal.CurrentTotal;
  86.  
  87. Dictionary<KeyValuePair<string, int>, object>
  88.  
  89. public class Triple<T, U, V>
  90. {
  91. public T First {get;set;}
  92. public U Second {get;set;}
  93. public V Third {get;set;}
  94. }
Add Comment
Please, Sign In to add comment