f# - Why is use better than using? -


according last sentence on this msdn page use preferred on using. i've heard elsewhere (this answer, example). why this? realize use added later. what's difference? on surface, using seems more useful because can control when dispose() called, , can explicitly ignore bound value (e.g., (fun _ -> ...)) if needed.

i think reason preferring use syntax simpler. many other language constructs expressed functions (e.g. try .. with, for, while, ...). if language designers added simpler syntax, why not use it...

as wrote in earlier answer referenced, can precisely control scope when using use. (and way, can use in constructors of object expressions class declarations.) of time, automatic behavior fine (which makes construct simpler using in c#).

whether you'll use use or using in situations need control scope explicitly matter of personal taste. if don't explicit scoping of use (which looks bit weird, admit, works fine me), can use using.

edit: in class declaration, cannot example write:

type foo() =   use = new whatever()   // ... 

because scope of a (possibly) whole lifetime of instance. (although think useful , add automatic implementation of idisposable type). if use using, don't sort of trouble.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -