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

  • SEARCH
  • Home
  • 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 3935344
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:49:09+00:00 2026-05-19T23:49:09+00:00

I would like to know whether my use of using is correct. In the

  • 0

I would like to know whether my use of using is correct. In the using statmement, I am deciding whether or not the image should be used in the game.

Image imageOfEnemy;
using(imageOfEnemy=Bitmap.FromFile(path))
{
   // some stuff with the imageOfEnemy variable

}

From my understanding, I do not need to call Dispose now.

  • 1 1 Answer
  • 0 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-19T23:49:10+00:00Added an answer on May 19, 2026 at 11:49 pm

    using is a shorthand statement for IDisposable objects to simplify the try-finally block, with Dispose in the finally block.

    http://msdn.microsoft.com/en-us/library/yh598w02.aspx

    So yes, you don’t have to call Dispose ‘manually’ in this case.

    using System;
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (var example = new Example())
                {
                    //do something
                }
            }
        }
    
        class Example : IDisposable
        {
    
            public void Dispose()
            {
                //Do something
            }
        }
    }
    

    the Main method will be this in MSIL:

    .method private hidebysig static void Main(string[] args) cil managed
    {
        .entrypoint
        .maxstack 2
        .locals init (
            [0] class ConsoleApplication3.Example example,
            [1] bool CS$4$0000)
        L_0000: nop 
        L_0001: newobj instance void ConsoleApplication3.Example::.ctor()
        L_0006: stloc.0 
        L_0007: nop 
        L_0008: nop 
        L_0009: leave.s L_001b
        L_000b: ldloc.0 
        L_000c: ldnull 
        L_000d: ceq 
        L_000f: stloc.1 
        L_0010: ldloc.1 
        L_0011: brtrue.s L_001a
        L_0013: ldloc.0 
        L_0014: callvirt instance void [mscorlib]System.IDisposable::Dispose()
        L_0019: nop 
        L_001a: endfinally 
        L_001b: nop 
        L_001c: ret 
        .try L_0007 to L_000b finally handler L_000b to L_001b
    }
    

    You can see the try-finally handler and the Dispose call even if you are new to MSIL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know whether i can get the drive information using the
I would like to know whether it is possible to use a SELECT statement
i would like to know whether the following query is optimized? select SUM(payments.paid_amt) as
I would like to know whether I could perform a full outer join between
I would like to know whether this is actually possible in Android? When Android
I am developing a walkie-talkie application for Android, and would like to know whether
I would like to do the following. I don't know whether it's possible to
I would like to know how css works under the hood. Whether the html
Would like to know what a programmer should know to become a good at
I would like to know whether it is possible and good practice to report

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.