{"id":451,"date":"2019-01-15T10:39:48","date_gmt":"2019-01-15T10:39:48","guid":{"rendered":"https:\/\/blogs.ua.es\/jpm33\/?p=451"},"modified":"2019-01-15T10:39:48","modified_gmt":"2019-01-15T10:39:48","slug":"para-que-sirve-using-en-c","status":"publish","type":"post","link":"https:\/\/blogs.ua.es\/jpm33\/2019\/01\/15\/para-que-sirve-using-en-c\/","title":{"rendered":"Para que sirve using en c#"},"content":{"rendered":"<p>La instrucci\u00f3n <strong>using<\/strong>:<\/p>\n<pre><strong>using<\/strong>(<strong>var<\/strong> disposableObject = <strong>new<\/strong> object_that_implements_IDisposable()) { ... }<\/pre>\n<p>es una construcci\u00f3n usada para ahorra c\u00f3digo al usar una estructura que implemente <strong>IDisposable<\/strong> c\u00f3mo esta:<\/p>\n<pre><strong>var<\/strong> disposableObject = <strong>new<\/strong> object_that_implements_IDisposable()\r\n<strong>try<\/strong>\r\n{\r\n    ...\r\n}\r\n<strong>finally<\/strong>\r\n{\r\n    <strong>if<\/strong>(disposableObject != <strong>null<\/strong>)\r\n    {\r\n        ((IDisposable)your_object).Dispose();\r\n    }\r\n}<\/pre>\n<p>Esta instrucci\u00f3n s\u00f3lo tiene sentido para declarar objetos que implementen el interfaz <strong>IDisposable<\/strong><\/p>\n<p><strong>Referencia<\/strong>:\u00a0<a href=\"https:\/\/docs.microsoft.com\/es-es\/dotnet\/csharp\/language-reference\/keywords\/using-statement\">using (Instrucci\u00f3n, Referencia de C#)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>La instrucci\u00f3n using: using(var disposableObject = new object_that_implements_IDisposable()) { &#8230; } es una construcci\u00f3n usada para ahorra c\u00f3digo al usar una estructura que implemente IDisposable c\u00f3mo esta: var disposableObject = new object_that_implements_IDisposable() try { &#8230; } finally { if(disposableObject != &hellip; <a href=\"https:\/\/blogs.ua.es\/jpm33\/2019\/01\/15\/para-que-sirve-using-en-c\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3080,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[374,676],"tags":[278,154,236718],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-programacion","category-sin-categoria","tag-c","tag-ingenieria","tag-programacion-2"],"_links":{"self":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/users\/3080"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":3,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/451\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}