I want to write an extension method to filter all the people with towns in a people object with the towns in shop object
class people
string name
string town
class shops
string category
string town
i know i can write
var x = from p in people
from s in shops
where p.town == s.town
but i would like to know how to write
var x = from p in people.FilterByTown(p) or FilterByTown(p => p.town) or however it is!!
where FilterByTown is the extension method and all the magic works in there and the object i pass in gets compared with the shop object.
It needs to work with different objects being fed to the method
Hope that all makes sense, the code above is obviously pseudo!
Assuming you have 2 collections people and shops you can write this:
If you want to sort all classes by some arbitrary property you can try this version:
Of course you need to be sure that property is valid and both objects have it.