Does C# support the use of static local variables?

后端 未结 12 935
眼角桃花
眼角桃花 2020-12-14 17:28

Related: How do I create a static local variable in Java?


Pardon if this is a duplicate; I was pretty sure this would have been

12条回答
  •  一向
    一向 (楼主)
    2020-12-14 17:36

    Not in C#, only in Visual Basic .NET:

    Sub DoSomething()
      Static obj As Object
      If obj Is Nothing Then obj = New Object
      Console.WriteLine(obj.ToString())
    End Sub  
    

    VB.NET have lot of nice things that C# does not have, thats why I choose VB.NET.

提交回复
热议问题