{"id":1112,"date":"2023-06-12T15:07:03","date_gmt":"2023-06-12T15:07:03","guid":{"rendered":"https:\/\/www.naveedulhaq.com\/?p=1112"},"modified":"2023-06-15T19:38:42","modified_gmt":"2023-06-15T19:38:42","slug":"using-statement-in-c-properly-managing-resources","status":"publish","type":"post","link":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/","title":{"rendered":"&#8216;using&#8217; Statement in C#: Properly Managing Resources"},"content":{"rendered":"\n<p>In <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/tour-of-csharp\/\" target=\"_blank\" rel=\"noreferrer noopener\">C#<\/a>, the &#8216;using&#8217; statement provides a convenient way to ensure the proper disposal of resources, such as file handles, database connections, or network streams. This blog post will explore the &#8216;using&#8217; statement, its benefits, and how to use it effectively in your C# code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/06\/C-1024x576.png\" loading=\"lazy\" alt=\"C# Using Statement Feature Image\" class=\"wp-image-1115\" srcset=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/06\/C-1024x576.png 1024w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/06\/C-300x169.png 300w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/06\/C-768x432.png 768w, https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2023\/06\/C.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The Purpose of the &#8216;using&#8217; Statement<\/h2>\n\n\n\n<p>The &#8216;using&#8217; statement is primarily used for managing unmanaged resources that implement the IDisposable interface. It ensures that the Dispose method of an object is called, releasing any resources held by the object. By properly disposing of resources, you prevent memory leaks and ensure efficient resource utilization.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Usage of the &#8216;using&#8217; Statement<\/h2>\n\n\n\n<p>Here&#8217;s a basic example of using the &#8216;using&#8217; statement:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using (StreamReader reader = new StreamReader(\"file.txt\"))\n\n{\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Perform file operations\n\n&nbsp;&nbsp;&nbsp;&nbsp;string line = reader.ReadLine();\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ ...\n\n}<\/code><\/pre>\n\n\n\n<p>In this example, the &#8216;using&#8217; statement creates an instance of the StreamReader class and assigns it to the &#8216;reader&#8217; variable. Within the &#8216;using&#8217; block, you can perform file operations using the &#8216;reader&#8217; object. Once the block is exited, the Dispose method of the &#8216;reader&#8217; object is automatically called, releasing the associated file handle.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of Using the &#8216;using&#8217; Statement<\/h2>\n\n\n\n<p>The &#8216;using&#8217; statement offers several benefits in managing resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Automatic Disposal:<\/strong> The &#8216;using&#8217; statement ensures that Dispose is called even if an exception occurs within the block. It guarantees proper cleanup and resource release, preventing resource leaks.<\/li>\n\n\n\n<li><strong>Readability and Scoping: <\/strong>By encapsulating resource usage within a &#8216;using&#8217; block, you explicitly define the scope of resource utilization. It improves code readability and helps prevent accidental resource misuse.<\/li>\n\n\n\n<li><strong>Simplifies Code:<\/strong> The &#8216;using&#8217; statement eliminates the need for manual resource cleanup code, making your code more concise and reducing the likelihood of coding errors.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Custom Types and the IDisposable Interface<\/h2>\n\n\n\n<p>To use the &#8216;using&#8217; statement with custom types, ensure that the types implement the IDisposable interface. The IDisposable interface includes the Dispose method, which you should implement to release any resources held by your custom type.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CustomResource : IDisposable\n\n{\n\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Implement IDisposable interface\n\n&nbsp;&nbsp;&nbsp;&nbsp;public void Dispose()\n\n&nbsp;&nbsp;&nbsp;&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Dispose of resources here\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Nested &#8216;using&#8217; Statements<\/h2>\n\n\n\n<p>You can also nest &#8216;using&#8217; statements to handle multiple resources. This allows for the proper management of multiple resources, ensuring that each resource is disposed of correctly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using (FileStream fileStream = new FileStream(\"file.txt\", FileMode.Open))\n\n{\n\n&nbsp;&nbsp;&nbsp;&nbsp;using (StreamReader reader = new StreamReader(fileStream))\n\n&nbsp;&nbsp;&nbsp;&nbsp;{\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ Perform file operations\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string line = reader.ReadLine();\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/ ...\n\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n}<\/code><\/pre>\n\n\n\n<p>In this example, both the &#8216;FileStream&#8217; and &#8216;StreamReader&#8217; objects are automatically disposed of in the correct order, regardless of any exceptions that may occur.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The &#8216;using&#8217; in C# provides a convenient and reliable way to manage resources and ensure their proper disposal. By using the &#8216;using&#8217;, you can prevent resource leaks, simplify your code, and improve readability. Remember to implement the IDisposable interface for custom types requiring resource management. Embrace the &#8216;using&#8217; to write cleaner and more efficient code while effectively managing resources in your C# applications.<\/p>\n\n\n\n<p>To check out more useful C# \/ ASP.NET tutorials, click <a href=\"https:\/\/www.naveedulhaq.com\/index.php\/category\/dot-net-core\/\" target=\"_blank\" rel=\"noreferrer noopener\">Here!<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C#, the &#8216;using&#8217; statement provides a convenient way to ensure the proper disposal of resources, such as file handles, database connections, or network streams&#8230;.<\/p>\n","protected":false},"author":3,"featured_media":641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[11,8,62,37,32,56],"class_list":["post-1112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net-core","tag-dot-net-core","tag-dot-net-framework","tag-asp-net","tag-c","tag-developer","tag-visual-studio"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>&#039;using&#039; Statement in C#: Properly Managing Resources - Naveed Ul-Haq&#039;s blog<\/title>\n<meta name=\"description\" content=\"The &#039;using&#039; statement is primarily used for managing unmanaged resources that implement the IDisposable interface.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"&#039;using&#039; Statement in C#: Properly Managing Resources - Naveed Ul-Haq&#039;s blog\" \/>\n<meta property=\"og:description\" content=\"The &#039;using&#039; statement is primarily used for managing unmanaged resources that implement the IDisposable interface.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/\" \/>\n<meta property=\"og:site_name\" content=\"Naveed Ul-Haq&#039;s blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-12T15:07:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-15T19:38:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png\" \/>\n\t<meta property=\"og:image:width\" content=\"240\" \/>\n\t<meta property=\"og:image:height\" content=\"240\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abdul Mannan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abdul Mannan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/\"},\"author\":{\"name\":\"Abdul Mannan\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/8babf3cd198e47e5c727f67880ea7977\"},\"headline\":\"&#8216;using&#8217; Statement in C#: Properly Managing Resources\",\"datePublished\":\"2023-06-12T15:07:03+00:00\",\"dateModified\":\"2023-06-15T19:38:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/\"},\"wordCount\":442,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/dd6db5980b965fcae41e096d357c65c9\"},\"image\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"keywords\":[\".net core\",\".net framework\",\"asp.net\",\"c#\",\"developer\",\"visual-studio\"],\"articleSection\":[\".NET\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/\",\"url\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/\",\"name\":\"'using' Statement in C#: Properly Managing Resources - Naveed Ul-Haq&#039;s blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"datePublished\":\"2023-06-12T15:07:03+00:00\",\"dateModified\":\"2023-06-15T19:38:42+00:00\",\"description\":\"The 'using' statement is primarily used for managing unmanaged resources that implement the IDisposable interface.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"contentUrl\":\"https:\\\/\\\/www.naveedulhaq.com\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/240px-.NET_Logo.svg_.png\",\"width\":240,\"height\":240,\"caption\":\".net\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/index.php\\\/dot-net-core\\\/using-statement-in-c-properly-managing-resources\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.naveedulhaq.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"&#8216;using&#8217; Statement in C#: Properly Managing Resources\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#website\",\"url\":\"https:\\\/\\\/www.naveedulhaq.com\\\/\",\"name\":\"Naveed Ul-Haq's blog\",\"description\":\"AI, Optimizely, Azure &amp; more\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/dd6db5980b965fcae41e096d357c65c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.naveedulhaq.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/dd6db5980b965fcae41e096d357c65c9\",\"name\":\"Naveed Ul-Haq\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\",\"caption\":\"Naveed Ul-Haq\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g\"},\"description\":\"I lead engineering delivery teams for digital commerce and digital experience platforms, combining hands-on architecture experience with strong delivery governance. Over 20+ years, I\u2019ve built and led cross\u2011functional teams (engineering, BA, QA) delivering modern cloud solutions on Azure, microservices, APIs and eCommerce\\\/CMS platforms. My recent focus includes AI-enabled commerce automation: product ingestion and enrichment workflows, content optimisation for SEO and shopping feeds, and agentic tooling to improve marketing and accessibility workflows. I\u2019m passionate about building high-performing teams, establishing quality\\\/release standards, and delivering measurable outcomes across performance, reliability, and speed of change.\",\"sameAs\":[\"https:\\\/\\\/www.naveedulhaq.com\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/naveedulhaq\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.naveedulhaq.com\\\/#\\\/schema\\\/person\\\/8babf3cd198e47e5c727f67880ea7977\",\"name\":\"Abdul Mannan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g\",\"caption\":\"Abdul Mannan\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"'using' Statement in C#: Properly Managing Resources - Naveed Ul-Haq&#039;s blog","description":"The 'using' statement is primarily used for managing unmanaged resources that implement the IDisposable interface.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/","og_locale":"en_GB","og_type":"article","og_title":"'using' Statement in C#: Properly Managing Resources - Naveed Ul-Haq&#039;s blog","og_description":"The 'using' statement is primarily used for managing unmanaged resources that implement the IDisposable interface.","og_url":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/","og_site_name":"Naveed Ul-Haq&#039;s blog","article_published_time":"2023-06-12T15:07:03+00:00","article_modified_time":"2023-06-15T19:38:42+00:00","og_image":[{"width":240,"height":240,"url":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","type":"image\/png"}],"author":"Abdul Mannan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Abdul Mannan","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#article","isPartOf":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/"},"author":{"name":"Abdul Mannan","@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/8babf3cd198e47e5c727f67880ea7977"},"headline":"&#8216;using&#8217; Statement in C#: Properly Managing Resources","datePublished":"2023-06-12T15:07:03+00:00","dateModified":"2023-06-15T19:38:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/"},"wordCount":442,"commentCount":0,"publisher":{"@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/dd6db5980b965fcae41e096d357c65c9"},"image":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#primaryimage"},"thumbnailUrl":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","keywords":[".net core",".net framework","asp.net","c#","developer","visual-studio"],"articleSection":[".NET"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/","url":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/","name":"'using' Statement in C#: Properly Managing Resources - Naveed Ul-Haq&#039;s blog","isPartOf":{"@id":"https:\/\/www.naveedulhaq.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#primaryimage"},"image":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#primaryimage"},"thumbnailUrl":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","datePublished":"2023-06-12T15:07:03+00:00","dateModified":"2023-06-15T19:38:42+00:00","description":"The 'using' statement is primarily used for managing unmanaged resources that implement the IDisposable interface.","breadcrumb":{"@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#primaryimage","url":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","contentUrl":"https:\/\/www.naveedulhaq.com\/wp-content\/uploads\/2021\/11\/240px-.NET_Logo.svg_.png","width":240,"height":240,"caption":".net"},{"@type":"BreadcrumbList","@id":"https:\/\/www.naveedulhaq.com\/index.php\/dot-net-core\/using-statement-in-c-properly-managing-resources\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.naveedulhaq.com\/"},{"@type":"ListItem","position":2,"name":"&#8216;using&#8217; Statement in C#: Properly Managing Resources"}]},{"@type":"WebSite","@id":"https:\/\/www.naveedulhaq.com\/#website","url":"https:\/\/www.naveedulhaq.com\/","name":"Naveed Ul-Haq's blog","description":"AI, Optimizely, Azure &amp; more","publisher":{"@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/dd6db5980b965fcae41e096d357c65c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.naveedulhaq.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/dd6db5980b965fcae41e096d357c65c9","name":"Naveed Ul-Haq","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g","caption":"Naveed Ul-Haq"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/362536aba6cc66917d7558cacd015a81c7cdf1a69b9a28c994764847c487b692?s=96&d=mm&r=g"},"description":"I lead engineering delivery teams for digital commerce and digital experience platforms, combining hands-on architecture experience with strong delivery governance. Over 20+ years, I\u2019ve built and led cross\u2011functional teams (engineering, BA, QA) delivering modern cloud solutions on Azure, microservices, APIs and eCommerce\/CMS platforms. My recent focus includes AI-enabled commerce automation: product ingestion and enrichment workflows, content optimisation for SEO and shopping feeds, and agentic tooling to improve marketing and accessibility workflows. I\u2019m passionate about building high-performing teams, establishing quality\/release standards, and delivering measurable outcomes across performance, reliability, and speed of change.","sameAs":["https:\/\/www.naveedulhaq.com","https:\/\/www.linkedin.com\/in\/naveedulhaq\/"]},{"@type":"Person","@id":"https:\/\/www.naveedulhaq.com\/#\/schema\/person\/8babf3cd198e47e5c727f67880ea7977","name":"Abdul Mannan","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7021bf97f2da3c29882f0e194e341d6abcc2b18abbbbf1e8ea688017b2323d21?s=96&d=mm&r=g","caption":"Abdul Mannan"}}]}},"_links":{"self":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/posts\/1112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/comments?post=1112"}],"version-history":[{"count":0,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/posts\/1112\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/media\/641"}],"wp:attachment":[{"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/media?parent=1112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/categories?post=1112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.naveedulhaq.com\/index.php\/wp-json\/wp\/v2\/tags?post=1112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}