ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  OOPS
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
How is the using() pattern useful? What is IDisposable? How
does it support deterministic finalization? 
 Question Submitted By :: Gvsk
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
Answer
# 1
The using statement defines a scope at the end of which an 
object will be disposed.

How to use
using (expression | type identifier = initializer) statement
where: 

expression 
An expression you want to call Dispose on upon exiting the 
using statement. 

type 
The type of identifier. 

identifier 
The name, or identifier, of the type type. It is possible 
to define more than one identifier of type type. Precede 
each identifier = initializer with a comma. 

initializer 
An expression that creates an object. 

statement 
The embedded statement or statements to executed. 

You create an instance in a using statement to ensure that 
Dispose is called on the object when the using statement is 
exited. A using statement can be exited either when the end 
of the using statement is reached or if, for example, an 
exception is thrown and control leaves the statement block 
before the end of the statement.

The object you instantiate must implement the 
System.IDisposable interface.

Example 
// cs_using_statement.cs
// compile with /reference:System.Drawing.dll
using System.Drawing;
class a
{
   public static void Main()
   {
      using (Font MyFont = new Font("Arial", 10.0f), 
MyFont2 = new Font("Arial", 10.0f))
      {
         // use MyFont and MyFont2
      }   // compiler will call Dispose on MyFont and 
MyFont2

      Font MyFont3 = new Font("Arial", 10.0f);
      using (MyFont3)
      {
         // use MyFont3
      }   // compiler will call Dispose on MyFont3

   }
}
Reference Link: http://msdn2.microsoft.com/en-
us/library/yh598w02(VS.71).aspx
 
Is This Answer Correct ?    0 Yes 0 No
Chirantan
 

 
 
 
Other OOPS Interview Questions
 
  Question Asked @ Answers
 
How would you stop a class from class from being derived or inherited. Ness-Technologies7
What is a scope resolution operator? HP4
What is OOPS and How it is different from Procedural Programming ? HP10
When will a constructor executed?  2
what is multithreading in c++ , what is difference between multithreading and singlethreading.  1
what is an instance of a class  2
What is Iteration Hierarchy? What is what is Object behavioral concept?  1
Explain polymorphism? What r the types of polymorphism? pls give examples? HCL2
In c++ there is only virtual destructors, no constructors. Why?  2
Difference between realloc() and free? HP3
What is the difference between an object and a class?  2
what is virtual function? Infosys11
How is exception handling carried out in c++?  1
When is a memory allocated to a class?  3
who is the founder of c++?  1
What is an orthogonal base class?  1
What does the code "cout<<(0==0);" print? 1) 0 2) 1 3) Compiler error: Lvalue required  5
What is the difference between declaration and definition?  6
What is polymorphism? Explain with an example.  7
What are the advantages of inheritance?  2
 
For more OOPS Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com