Lambda Expression Using Statement with object


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

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


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.