structure

  • Thread starter Thread starter Reza Alirezaei
  • Start date Start date
R

Reza Alirezaei

can somebody tell me what kind of structure is this,I haven't seen such a
structure in C# yet:

using(ISerializer questionSerializer = new QuestionSerializer())

{

oeq = (OpenEndedQuestion) questionSerializer.Deserialize(context, new
Guid(Request["QuestionGID"]));

}
 
Reza,

Are you referring to the using statement? If that is the case, then
what that does is take a type that implements (or derives) from IDisposable.
When the block that follows the using statement is exited for any reason
(the code just exits, a return statement, an exception thrown), then the
Dispose method is called on the implementation of IDisposable.

Hope this helps.
 
{this is a nice little bit of info from a web site that explains what I
think you are asking}

C# has a nice statement that automates dealing with the Dispose method. You
can use this statement with any class that implements IDisposable. If the
class does not implement IDisposable, you will get a compile error

using (MyClass myClass = new MyClass())
{
// do something with myClass
}

The above C# code is equivalent to :

MyClass myClass = new MyClass() ;

try
{
// do something with myClass
}
finally
{
myClass.Dispose() ;
}

As you can see, Dispose will always be called, even in the case of an
exception.

You can nest using statements and you can include multiple comma-separated
instantiations in the parantheses.


--

--

Br,
Mark Broadbent
mcdba , mcse+i
=============
 
Back
Top