Guest User

Untitled

a guest
Oct 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. public static TO ConvertValue<TI, TO>(TI value) => (TO)Convert.ChangeType(value, typeof(TO));
  2.  
  3. public static void Deconstruct<TI, TO>(this IEnumerable<TI> src, out TO p1, out TO p2) {
  4. var e = src.GetEnumerator();
  5. p1 = e.MoveNext() ? ConvertValue<TI,TO>(e.Current) : default(TO);
  6. p2 = e.MoveNext() ? ConvertValue<TI,TO>(e.Current) : default(TO);
  7. }
  8.  
  9. (int p1, int p2) = new int[] { 1, 2, 3, 4 };
  10.  
  11. Ext.Deconstruct(new int[] { 1, 2, 3 }, out p1, out p2);
Add Comment
Please, Sign In to add comment