Generic Convert


/ Published in: C#
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.