P
Prateek
Is there a C# equivalent to static keyword in VB.NET? Or, some way to implement the exactly same functionality in C#?
Is there a C# equivalent to static keyword in VB.NET? Or, some way to implement the exactly same functionality in C#?
Mark Broadbent said:That is not true. The equivalant in VB is Shared. The difference is that VB
is not as strict and allows the member to be referenced through the instance
or through the class HOWEVER the member is still static within the class
Mark Broadbent said:I'll keep my mouth shut! Sorry all, I'll learn to read the posts properly
next time.
Mark Broadbent said:I'll keep my mouth shut! Sorry all, I'll learn to read the posts properly
next time.
Prateek said:Isn't there any way to implement this functionality.. suppose there is a
function and I want to know how many times it is called.. I do not want to
use a global variable or byref parameter.. I can do that easily in VB.NET
using static..
but in c#, how?
Jon said:Use a static or instance variable - and if the method really *does*
have state which isn't appropriate to put in the class, then consider
encapsulating it in a separate class.
Not that I am aware of!the CLI has it
VB.NET exposes it by adding two (hidden) instance fields to your class, plusVB.NET exposes it
Kevin P. Fleming said:This is one thing I am not thrilled about C#... C had it, the CLI has
it
VB.NET exposes it, but C# does not. If I have a method that needs to
act differently when it's recursing vs. not, I'd hate to have to the
variable that indicates that outside the method body.
Jon said:Like Jay, I don't believe this is true. Try running ildasm on a VB.NET
program which has a static local variable.
So pass the variable in as a parameter, by reference if necessary.
There are always ways round this kind of thing.
Kevin P. Fleming said:Yes, agreed that there are multiple ways to do the job. However, passing
it in as a parameter now means that the caller will know about it and
must pass a suitable "initial" value, or a second method that acts as a
wrapper for the recursing method must be created to hide this from
callers outside the type. I'm not saying this is terrible, it's just not
pretty and this idiom is used a great deal outside the C# world, so it's
unfortunate that the language does not implement a simple method to do it.
OO, IMO. Just because it's used outside OO doesn't mean it should be
included in an OO language. The things which have state in OO are
Eric said:How in the world did local statics get the axe, but labels and "goto" made
it in?
Ravichandran J.V. said:Shared