Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'using' a C# keyword?

If an object realizes IDisposable in C# one can write

using(DisposableFoo foo = new DisposableFoo())

I've always wondered why the using looks like a C# keyword, but requires an interface defined in the .Net framework. Is using a keyword (in this context, obviously it is for defining your library imports), or has Microsoft overloaded it's use in Visual Studio/.Net framework? I wouldn't have expected a C# keyword to depend on a library.

like image 522
RichK Avatar asked Oct 03 '10 10:10

RichK


2 Answers

it's a keyword construct that requires a IDisposable, because it acts on the object's Dispose method. It's not too far fetched to have a keyword use a type. If is a keyword and it requires a condition (IE: Boolean) type.

like image 88
Tony Abrams Avatar answered Sep 19 '22 11:09

Tony Abrams


According to Microsoft it's a keyword.

like image 26
Brian Agnew Avatar answered Sep 23 '22 11:09

Brian Agnew