Posted By

rengber on 11/10/08


Tagged

Converter Generic


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Generic Convert


 / Published in: C#
 

URL: http://msdn.microsoft.com/en-us/library/73fe8cwf(VS.80).aspx

This technique can convert a list of one type into a list of another in a single line given and instance to instance conversion method to be passed to the delegate constructor.

  1. public class LendingRates
  2. {
  3. public List<BLRate> GetLendingRates()
  4. {
  5.  
  6. . . .
  7.  
  8. List<DLRate> ldlr = dlObject.GetLendingRates(date);
  9.  
  10. List<BLRate> lblr = ldar.ConvertAll(new Converter<DLRate, BLRate>(RateToRateConverterMethod));
  11. return lblr
  12. }
  13.  
  14. . . .
  15.  
  16. public static BLRate RateToRateConverterMethod(DLRate dr)
  17. {
  18. return new BLRate(dr.Name, dr.Value);
  19.  
  20. }
  21. }

Report this snippet  

You need to login to post a comment.