C# Programmers! - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › C# Programmers! (968 Views)
| C# Programmers! by lordbenax(op): 6:03pm On Nov 14, 2008 |
Yo! C# programmers, i have a little problem. Though C# is not my primary programming langauge, I know C# a little. I av also bin able to convert a few C# codes to vb.net and java. But there is a key word i keep coming across and i don't know its function in C#. it is the 'using' keyword. I know like in C++ it is used for class reference but i come across it in cases like this
I would like the C# programmers to help me out! I want to know that keyword's function in instances like this! Thanks!! |
| Re: C# Programmers! by Kobojunkie: 6:34pm On Nov 14, 2008 |
the Using Statement applies to objects that implement IDisposable interface, and is similar to the Try_catch Or Try_catch_Finally block in C#. The Using Statement allows for the compiler to handle the creation and disposal of the object, as well as exception issues implicitly. ie. Code 1 and 2 Below are similar and perform the same function. Code 1
Code 1
|
| Re: C# Programmers! by lordbenax(op): 7:07pm On Nov 14, 2008 |
Thanks Kobojunkie! It is so unbelievable that that function is just similar to the TRY CATCH STATEMENT. That means i can use Try Catch and just dispose the object myself. How revealing! |
| Re: C# Programmers! by Kobojunkie: 11:18pm On Nov 14, 2008 |
You don't need to dispose of the object yourself as the CLR's garbage collector does a good job of that. But should you have to create an object that you would want disposed specially, then you can implement the Idisposable interface, use the Using statement and that prompts the GC when the scope is exited. Feel free to use whichever method you want to. Note: the actual disposal of objects is handled implicity by the GC regardless of which method you choose. |
C# Programmers, Solve This Question • C++ Programmers Help!!!!!!!!!!!!!!!!!!!!!!!! • for beginner C++ Programmers • 2 • 3 • 4
Help In Php,java, Html And C# • Ego Trolls Of The Programming Section • How Rewarding Is App For New Generation Smart Phones To Local Developers?