C# Call Different Functions in Core Function -


in c#, how can simplify getdata1() , getdata2() 1 line function only? please see comments in getdata1 , getdata2, have 2 write 3 lines in each function, use getdatacore simplify it.

    public ienumerable<int> getdatacore(function passinfunction)     {         // many other steps         foreach (var sensor in sensors)         {             yield return sensor.passinfunction();         }     }      public ienumerable<int> getdata1()     {         // many other steps         // todo: use          // return getdatacore(getdata1);         foreach (var sensor in sensors)         {             yield return sensor.getdata1();         }     }      public ienumerable<int> getdata2()     {         // many other steps         // todo: use          // return getdatacore(getdata1);         foreach (var sensor in sensors)         {             yield return sensor.getdata2();         }     } 

there's no need write own method project of items in sequence using selector passed delegate. linq created such method you, called select:

public ienumerable<int> getdata1() {     return sensors.select(sensor => sensor.getdata1()); } 

but, answer question anyway, if function func<sensor, int>, pass in method takes sensor , transforms integer, in each of getdatax methods, using lambada, shown above.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -