c# - Using statement best practice -


This can be a silly question, but since I can not give it my answer, I will ask it here.

We have a module that we want to use in an HTC Handler (Web app is written in ASP.NET in C #) and this module is written in IDisposable Interface Then there is a general approach to using the module:

 using  (var module = new ModuleName (param1, param2, param3)) {}  
< P> Is it better to put any code into variables, which we are using only using this statement or before the code reference:

Is it better (and why) first approach or second approach:

first approach

 using  (var module = new) Modulenme (param1, param2, Prm3)) {brick A = Rikvestkgetpram & lt; Int & gt; ("ANumber"); String B = Request GETParam & lt; String & gt; ("Bistring"); // Other criteria included in other requests}  

second approach

  int a = request GETParam & lt; Int & gt; ("a number"); String B = Request GETParam & lt; String & gt; ("Bistring"); // and http requests using other parameters (var module = new ModuleName (param1, param2, param3)) {}  

If there is no technical reason - and this is a There is opinion based judgment - we should like the first approach of another approach or vice versa, please tell me, to delete my post.

It depends on you using using > Those variables are needed outside the scope of -statement if yes, then you need to declare them out in any way. If not, then declare them by using

Why? It is about readability, unsuccessful and refactoring.

This is not only for using , but in general the Scope and Variable Declaration. Read:


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -