Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How is the using() pattern useful? What is IDisposable? How
does it support deterministic finalization?

Answer Posted / chirantan

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 ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the sylabus for priliminaries?

2122


Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.

3035


Can static class have constructor?

984


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

2071


What is the real time example of encapsulation?

1007


What is and I oop mean?

1108


What is abstraction in oops?

984


Whats oop mean?

989


What is overloading in oops?

1092


What are the 3 principles of oop?

1054


What is static modifier?

1127


What is abstract class in oops?

974


What is difference between multiple inheritance and multilevel inheritance?

1104


Is abstract thinking intelligence?

979


What are the three parts of a simple empty class?

1980