PDA

View Full Version : using .... آن هم وسط برنامه



Babak-Aghili
یک شنبه 15 خرداد 1384, 00:39 صبح
سلام.

توی کتاب C sharp Bible ( اول صفحه ی 223 ) یک همچین چیزی نوشته ... بعنوان بدنه تابع Main .... البته خب یک سری کلاسهای دیگه هم تعریف کرده ....

میشه بفرمایید این دیگه چیه ؟ کاربردش چیه ؟ و خلاصه یک توضیحی بدهید /

( بابا ! این سی شارپ چقدر سوراخ سنبه داره ! ) .




using ( MyClass MyObject = new MyClass () )

Babak-Aghili
دوشنبه 16 خرداد 1384, 00:50 صبح
شما هم با این موضوع برخورد نکرده اید ؟ :گیج:

---------------------
(البته عذر من موجه است ... چون چهار روز است که سی شارپ را شروع کردم . :mrgreen: )

سار
دوشنبه 16 خرداد 1384, 03:11 صبح
خود برنامه رو میتونی بنویسی که ببینم از این کد چه استفاده ای شده. :reading:

برای من هم خیلی جالبه

quack
دوشنبه 16 خرداد 1384, 10:20 صبح
یه سر به MSDN بزنی بد نیست

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.
Remarks
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

}
}