Last active
October 15, 2015 04:04
-
-
Save nutrino/a5704f39b89a60dbabab to your computer and use it in GitHub Desktop.
LINQ Where Duck Typing Test
http://ericlippert.com/2014/01/02/what-is-duck-typing/comment-page-1/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Customer | |
{ | |
public string City { get; set; } | |
} | |
class Customers | |
{ | |
private Customer c; | |
public Customers() | |
{ | |
c = new Customer(); | |
c.City = "New York"; | |
} | |
public Customer Where(Func<Customer, bool> predicate) | |
{ | |
if (predicate(c) == true) | |
return c; | |
else | |
return null; | |
} | |
} | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var customers = new Customers(); | |
var list = from c in customers where c.City == "London" select c; | |
Console.WriteLine("Hello World " + ((list != null) ? list.ToString() : "null")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment