c# - Using a function as an Action argument -


for scenario have list<t> removable i'm using remove items variable observablecollection<t> collection. don't believe can use except method here because need collection create change events.

removable.foreach(profile => collection.remove(profile)); 

is there better syntax passing function action argument? in java pass in method:

removable.stream().foreach(collection::remove); 

in java can pass function if signature of function matches, in c#, no, there's no better way if function signature not same, in java.

but, can create extension accept return type, this:

public static class extensions {     public static void foreach<tin, tout>(this list<tin> thecollection, func<tin, tout> processfunction)     {         thecollection.foreach((item) => processfunction(item));     } } 

then can

removable.foreach<string, bool>(collection.remove); 

this not faster more readable.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -