Last post Sep 22, 2007 12:22 AM by David Anton
Jan 06, 2006 07:12 PM|jrandomuser|LINK
VB.net has a Shared which equates to C# Static however VB.net also has a Static which is exposes a feature I can not seem to replicate in c#. The following is a simple example of some vb.net code. a will = 2 at the end of this. What is the code reproduce
this in C#
a = y()
x += 1
Jan 06, 2006 09:40 PM|cubeberg|LINK
There's no actual
equivalent of VB Static in C#. I would say that the best way to handle this would be to declare a C# static integer outside of your function as part of your form. Just keep in mind that the static variable isn't specific to that session. It's specific
to the instance of your application.
Jan 06, 2006 10:46 PM|bitmask|LINK
Jan 07, 2006 04:13 AM|David Anton|LINK
Static local variables in Shared methods should convert to C# static class variables.
Static local variables in non-Shared methods should convert to C# non-static class variables.
Instant C#: VB.NET to C# converter
Instant VB: C# to VB.NET converter
Instant C++: C# to C++ converter and VB to C++ converter
Instant J#: VB.NET to J# converter
Clear VB: Cleans up VB.NET code
Sep 21, 2007 08:52 PM|christophilus|LINK
Hmm... VB's static option is really convenient, and doesn't do the same thing as the C# static class variables.
They are more like a private, class-level variable that can only be accessed by a certain method (the method in which they are declared) and can be instantiated the first time that method is called rather than during class construction.
The lack of this feature in C# really bugs me.
Sep 22, 2007 12:22 AM|David Anton|LINK
It can be useful.
And it's not just a VB quirk. Other languages - notably C++ - also have it.