I was curious what is the scope of variables declared inside the constructor of classes that are not data members of this class?
For example, if a constructor needs an iterating int i, will this variable be destroyed after the constructor completes, or is it global for the program?
Thanks!
In this sense, the constructor is like any other function - any variable declared inside has the usual limitations in scope, and all of them necessarily go beyond the scope and are destroyed after the constructor completes.
, , "" . .
, , .
, , ( , , ): , ( "", " " ).
am, , , ( , , ): , .
public MyClass() { int i = 0; // i is only available inside this constructor. // It can't be used in any other function of this class or any other. }
, , , . .
The area can be either static (lexical) or dynamic. Most languages use a lexical region, which means that the region is defined by the program text (for example, "inside the set of curly braces where it is defined"), and not by the value of what you wrote.
http://en.wikipedia.org/wiki/Scope_(programming)
Source: https://habr.com/ru/post/1705476/More articles:Removing an Image Associated with a Control - c #Как я могу создать заголовок мыла, как это? - soapHow do you test the code you wrote yourself? - unit-testingLinqPad Function - Does VS Do It? - c #Asp.net Global Variables - .netAchieving seam deployment with an Intellij idea - intellij-ideaУстранение неполадок PDO: ошибка не обнаружена при выполнении подготовленного оператора - phpFlash compiler / interpreter optimization - optimizationSslStream.DataAvailable is not a valid function - c #How can I order referenced objects from a Datastore Google App Engine request? - pythonAll Articles