- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of ‘Using’ statement in C#?
The using statement is used to set one or more than one resource. These resources are executed and the resource is released. The statement is also used with database operations.
The main goal is to manage resources and release all the resources automatically.
Let us see an example wherein “A” would print first since the SystemResource is allocated first.
Example
using System; using System.Text; class Demo { static void Main() { using (SystemResource res = new SystemResource()) { Console.WriteLine("A"); } Console.WriteLine("B"); } } class SystemResource : IDisposable { public void Dispose() { Console.WriteLine("C"); } }
Output
A C B
Advertisements