User Tools

Site Tools


notes:csharp:anonymoustypes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:csharp:anonymoustypes [2020/06/17]
leszek
notes:csharp:anonymoustypes [2020/06/17] (current)
leszek
Line 34: Line 34:
 </​code>​ </​code>​
  
-Pass an anonymous type to a generic method:+Pass an anonymous type (a function) ​to a generic method
 <code csharp> <code csharp>
 ... ...
Line 46: Line 46:
 </​code>​ </​code>​
  
 +Methods that take a function as a parameter or return a function are called **higher-order functions**.
  
 Anonymous types are commonly used with LINQ in the //select// clause of a query expression: Anonymous types are commonly used with LINQ in the //select// clause of a query expression:
Line 88: Line 89:
 // Use the names A and B. // Use the names A and B.
 (int A, int B) p2 = p; (int A, int B) p2 = p;
 +</​code>​
 +
 +Return a tuple from a function:
 +<code csharp>
 +(int X, int Y) GetPoint(int a, int b)
 +{
 +    ...
 +    return (a, b);
 +}
 +...
 +// Assign the return value to a tuple.
 +var p1 = GetPoint(1, 2);
 +
 +// Use deconstruction to assign the return values to different variables p and q.
 +(int p, int q) = GetPoint(3, 4);
 </​code>​ </​code>​
  
notes/csharp/anonymoustypes.txt ยท Last modified: 2020/06/17 by leszek