Monday 15 February 2010

c# 3.0 - C# 3.0 Tuple Equivalents (for poor men) -


I find myself occasionally in C # 3.0, searching for ways to emulate Tupl's concept . Over time, I have implemented many "poor people", some of them are here:

Original Object Array :

  Object [] Bad Tupale = New Object [] {EF, Bar, Falcon}; // Original object array  

more strongly typed , hello ...

  KeyWellPear & amp; type; Type A; Key val peer; Type B, Type C & gt; & Gt; PoorTuple;  

Applying a class which can be used to guess the type (raised from)

  public stable Class tuple {public stationary tubal & lt; T1, T2 & gt; & Lt; T1 foo, t2 times & gt; {New Tupal & lt; T1, T2 & gt; (Af, bar); }} // later: var data = tubel. Cret ("foo", 42);  

Question:

  1. Any other methods (or language of choice which lacks data structure) in C # 3.0 for a poor man's tubal

  2. What is the best method to get a tube in C # 3.0 - if anyone has a library recommendation then welcome it is.

  3. At what point (yes, generalization for me) does it mean to make a specific type instead of something like a list or a tuple? (Search of thumb rules)

You can create anonymous types Exclude useful names, do the same as Tuples:

  Child items with my items = myObjects. Select (x = & gt; new {name = x.Name, count = x.Children.Count ()});  

No comments:

Post a Comment