Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 561337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:26:22+00:00 2026-05-13T12:26:22+00:00

Possible Duplicates: Using the using statment in c# What is the C# Using block

  • 0

Possible Duplicates:
Using the using statment in c#
What is the C# Using block and why should I use it?

Just wondering what this means? I’ve seen lots of tutorials online that have the syntax:

using (SqlCeCommand cmd2 = new SqlCeCommand("SELECT city FROM cities JOIN states ON states.id=cities.state WHERE states.state='" + read.GetString(0) + "'", con))
{
  SqlCeDataReader readCities = cmd2.ExecuteReader();
  while (readCities.Read())
  {
    parent.Nodes.Add(readCities.GetString(0));
  }
}

Why is it used? I tried searching Google, but it comes up with the ‘using’ keyword which is used for including dll’s and other files.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:26:22+00:00Added an answer on May 13, 2026 at 12:26 pm

    The using statement

    using(var disposableObject = new object_that_implements_IDisposable()) { ... }
    

    is syntactic sugar for code similar to following:

    var disposableObject = new object_that_implements_IDisposable()
    try
    {
        ...
    }
    finally
    {
        if(disposableObject != null)
        {
            ((IDisposable)your_object).Dispose();
        }
    }
    

    This is only applicable for classes that implement IDisposable. It is helpful for cleaning up code where you have objects that take, for example, system resources (file handles, database connections, sockets, etc.) that need to be cleaned up after you are done to free the resource for the rest of the system.

    In theory, you could leave out the .Dispose() call, but then you would have to wait for the Garbage Collector to free the kept resources. The GC is awesome at knowing when to free objects to reclaim their memory usage, but it has no idea that it needs to free objects to have them give up other system resources. Thus, these critical resources might not be given up until after the GC decides it needs the memory used by the owner. Thus, you definitely want to dispose of your objects when you are done with them (if they are disposable)!

    As to why you’d use using over try/finally, it is purely a coder’s preference. I prefer using because you can cascade them:

    using(var a = new class())
    using(var b = new class())
    using(var c = new class())
    using(var d = new class())
    {
        ...
    }
    

    You’d need quite a few more lines of code to do that with try/finally.

    using has additional advantages as well. For example, whereas calling x.Dispose directly might throw a NullReferenceException if x is null, using(x) will not.

    See also:

    • Link
    • Using the using statement in C#
    • What is the C# Using block and why should I use it?
    • http://msdn.microsoft.com/en-us/library/yh598w02%28VS.80%29.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 352k
  • Answers 353k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Can you pull the calculations out to their own method… May 14, 2026 at 7:37 am
  • Editorial Team
    Editorial Team added an answer Looks to me like you're wrapping the map in an… May 14, 2026 at 7:37 am
  • Editorial Team
    Editorial Team added an answer If you're using ASP.NET with some jQuery, you could set… May 14, 2026 at 7:37 am

Related Questions

Possible Duplicate: What is the C# Using block and why should I use it?
Possible Duplicates: C/C++: Detecting superfluous #includes? How should I detect unnecessary #include files in
Possible Duplicate: Equivalence of “With…End With” in c#? There was one feature of VB
I'm C++ begginer. I did this excercise from Deitel's book: Use a one-dimensional array
Possible Duplicate: String vs StringBuilder I just revisited some of the books that I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.