When is a static variable created?

前端 未结 3 1127
耶瑟儿~
耶瑟儿~ 2020-12-19 11:02

Let\'s say I have a static variable in a function:

Private Sub SomeFunction()
    Static staticVar As String = _myField.Value
End Sub

When, e

3条回答
  •  [愿得一人]
    2020-12-19 11:56

    The VB.NET compiler creates a static (shared in VB.NET) class-level variable to maintain the value of "staticVar". So it's initialized like any other static/shared variable, on the first use of a static field of that class (or when you call this method).

    http://weblogs.asp.net/psteele/pages/7717.aspx

提交回复
热议问题