PDA

View Full Version : سوال: using چیست؟



ameysams
چهارشنبه 23 مرداد 1387, 19:04 عصر
با سلام اگر ممکن است یکی از دوستان توضیح دهدکه:
1-usingچیست؟
2-کی باید از اون استفاده کرد متشکرم

mostafaaa
چهارشنبه 23 مرداد 1387, 21:54 عصر
Sometimes your code requires an unmanaged resource, such as a file handle, a COM wrapper, or a SQL connection. AUsing block guarantees the disposal of one or more such resources when your code is finished with them. This makes them available for other code to use.
Managed resources are disposed of by the .NET Framework garbage collector (GC) without any extra coding on your part. You do not need a Using block for managed resources.
Behavior

AUsing block behaves like a Try...Finally construction in which the Try block uses the resources and the Finally block disposes of them. Because of this, the Using block guarantees disposal of the resources, no matter how you exit the block. This is true even in the case of an unhandled exception, except for a StackOverflowException.
The scope of every resource variable acquired by the Using statement is limited to the Using block.
If you specify more than one system resource in the Using statement, the effect is the same as if you nested Using blocks one within another.

salehbagheri
پنج شنبه 24 مرداد 1387, 11:37 صبح
Using يك كلمه رزرو شده در برنامه VB هست كه همانند Dim عمل مي كند، با اين تفاوت كه پس از اتمام كار، يعني بعد از End Using متغير اعلان شده را به كلي نابود مي كند.

استفاده از اين كلمه باعث كاهش فشار بروي سيستم و يا هاست مربوطه مي شود، پس بهتر از Dim است.