How is the using() pattern useful? What is IDisposable? How
does it support deterministic finalization?
Answer / 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 |
What are the components of marker interface?
1.explicit call for destructor 2.calling function inside a constructor. 3.base *b-new derived delete b; 4.delete p what it will delete. 5.size of base class and derived class int i,in base class and int j in derived. 6.int i-20 int main() { int i =5; printf("%d".::i); { int i =10; printf("%d".::i); } } 7.object slicing 8.new 9.function overloading(return type). 10.class base() { virtuval fun() { ----- } } class derivied:public base() { fun() { ----- } } int main() { derived d; } 11.how static function will call in C++? 12.default structures are in C++? 13.constructors should be in public . 14.virtuval constructor not exist. 15.multilevel inhritence. destructor order.
diff between Abstract class Interfaces?
what is the size of an empty class
What do you mean by variable?
What is difference between #define and const?
What are virtual functions?
what are the different types of qualifier in java?
why the memory allocated with new cant be freed using free()
write a program that takes input in digits and display the result in words from 1 to 1000
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
Why do we use oop?