Posted By

kwhite1975 on 09/10/13


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

danfinrud55


Lambda Expression Using Statement with object


 / Published in: C#
 

Snippet to show how to create a generic function to have a using/with statement for an object that has already been created.

  1. public static class Utilities
  2. {
  3. public static void Use<T>(this T item, Action<T> work)
  4. {
  5. work(item);
  6. }
  7. }
  8.  
  9. Object.InnerObject.Use( i => {
  10. i.Foo = bar;
  11. i.Text = "Set this here";
  12. });

Report this snippet  

You need to login to post a comment.