C# Using Statements

Recently C# added “using” statements that can replace “using” blocks in many scenarios. It lets you auto-dispose of a disposable object at the end of the current block, rather than defining a brand new block.

This reduces the number of nested blocks y…


This content originally appeared on DEV Community and was authored by Joe Enos

Recently C# added "using" statements that can replace "using" blocks in many scenarios. It lets you auto-dispose of a disposable object at the end of the current block, rather than defining a brand new block.

This reduces the number of nested blocks your code needs. It's not unusual to have two nested using blocks, and that pushes your code way over. Now, you just need to structure your code so that it disposes at the end of the block (method, if/else block, old-fashioned using block, even a custom block).


This content originally appeared on DEV Community and was authored by Joe Enos


Print Share Comment Cite Upload Translate Updates
APA

Joe Enos | Sciencx (2021-05-15T03:38:06+00:00) C# Using Statements. Retrieved from https://www.scien.cx/2021/05/15/c-using-statements/

MLA
" » C# Using Statements." Joe Enos | Sciencx - Saturday May 15, 2021, https://www.scien.cx/2021/05/15/c-using-statements/
HARVARD
Joe Enos | Sciencx Saturday May 15, 2021 » C# Using Statements., viewed ,<https://www.scien.cx/2021/05/15/c-using-statements/>
VANCOUVER
Joe Enos | Sciencx - » C# Using Statements. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/15/c-using-statements/
CHICAGO
" » C# Using Statements." Joe Enos | Sciencx - Accessed . https://www.scien.cx/2021/05/15/c-using-statements/
IEEE
" » C# Using Statements." Joe Enos | Sciencx [Online]. Available: https://www.scien.cx/2021/05/15/c-using-statements/. [Accessed: ]
rf:citation
» C# Using Statements | Joe Enos | Sciencx | https://www.scien.cx/2021/05/15/c-using-statements/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.