473,462 Members | 1,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

what's the equivalent

hey all,
vb has a static keyword for variables, what is charp's equivalent,please?

static tempVar as String

thanks,
rodchar
Nov 9 '06 #1
12 2231
rodchar wrote:
hey all,
vb has a static keyword for variables, what is charp's equivalent,please?

static tempVar as String
also static in C#

as in:

static string tempVar;

Arne
Nov 9 '06 #2
static is a C# keyword,
Its Shared in VB

Ciaran O'Donnell

"rodchar" wrote:
hey all,
vb has a static keyword for variables, what is charp's equivalent,please?

static tempVar as String

thanks,
rodchar
Nov 9 '06 #3
The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to retain
the value of a variable inside a function.

Shared and Static in VB.NET and C# respectively mean, when applied to a
variable, that all instances of the object share the same piece of data.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rodchar" wrote:
hey all,
vb has a static keyword for variables, what is charp's equivalent,please?

static tempVar as String

thanks,
rodchar
Nov 9 '06 #4
Peter Bromberg [C# MVP] wrote:
The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to retain
the value of a variable inside a function.
Like C ?

What about simply moving it outside the function (and make
it static if it is a static method) ?

Arne
Nov 9 '06 #5
You could certainly do that. But my point to the OP was, if you are comparing
against classic VB there is no direct equivalent:

http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Arne Vajhøj" wrote:
Peter Bromberg [C# MVP] wrote:
The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to retain
the value of a variable inside a function.

Like C ?

What about simply moving it outside the function (and make
it static if it is a static method) ?

Arne
Nov 9 '06 #6
thanks everyone for the great feedback.

"Peter Bromberg [C# MVP]" wrote:
You could certainly do that. But my point to the OP was, if you are comparing
against classic VB there is no direct equivalent:

http://msdn2.microsoft.com/en-us/library/z2cty7t8.aspx

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Arne Vajhøj" wrote:
Peter Bromberg [C# MVP] wrote:
The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to retain
the value of a variable inside a function.
Like C ?

What about simply moving it outside the function (and make
it static if it is a static method) ?

Arne
Nov 9 '06 #7
The "static" local variable in VB is not limited to "classic" VB, but is
alive and well in VB.NET also.
There is no C# equivalent. It can be replaced by a class-level instance or
static variable in C# (depending on whether the original method was an
instance or static method), but this doesn't quite capture the usefulness of
the local static variable.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Peter Bromberg [C# MVP]" wrote:
The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to retain
the value of a variable inside a function.

Shared and Static in VB.NET and C# respectively mean, when applied to a
variable, that all instances of the object share the same piece of data.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rodchar" wrote:
hey all,
vb has a static keyword for variables, what is charp's equivalent,please?

static tempVar as String

thanks,
rodchar
Nov 9 '06 #8
David Anton <Da********@discussions.microsoft.comwrote:
The "static" local variable in VB is not limited to "classic" VB, but is
alive and well in VB.NET also.
There is no C# equivalent. It can be replaced by a class-level instance or
static variable in C# (depending on whether the original method was an
instance or static method), but this doesn't quite capture the usefulness of
the local static variable.
It does, however, *exactly* capture the semantics - as that's what the
VB.NET compiler converts the code into.

Personally I'm glad that C# doesn't have statics. Persistent state
should be a property of types and objects, not methods. Whenever a
method feels like it needs state, consider whether that state is
inherently part of the object, or whether it should be part of a new
class in its own right, which the object has a reference to an instance
of.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 10 '06 #9

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:45***********************@news.sunsite.dk...
Peter Bromberg [C# MVP] wrote:
>The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to
retain the value of a variable inside a function.

Like C ?

What about simply moving it outside the function (and make
it static if it is a static method) ?
No if. C/C++ local statics are reused between all invocations, independent
of arguments (the this pointer is really an argument). So you can use a
global variable or a class static to get the same result.
>
Arne

Nov 10 '06 #10

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
David Anton <Da********@discussions.microsoft.comwrote:
>The "static" local variable in VB is not limited to "classic" VB, but is
alive and well in VB.NET also.
There is no C# equivalent. It can be replaced by a class-level instance
or
static variable in C# (depending on whether the original method was an
instance or static method), but this doesn't quite capture the usefulness
of
the local static variable.

It does, however, *exactly* capture the semantics - as that's what the
VB.NET compiler converts the code into.

Personally I'm glad that C# doesn't have statics. Persistent state
should be a property of types and objects, not methods. Whenever a
method feels like it needs state, consider whether that state is
inherently part of the object, or whether it should be part of a new
class in its own right, which the object has a reference to an instance
of.
Agreed. While in C/C++ local statics have a use, namely caching the result
of a complex calculation/database lookup/object instantiation/etc., the VB
semantics are different, introducing *instance* variables. That's just
wrong.

Really, static should never be used to change the meaning of the program,
only to cache the result of an initialization which would take the same
value every time anyway.
>
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 10 '06 #11
The class level variables simulate the functionality (our converters do
that), but I wouldn't say they capture the semantics well, since the
semantics of "local static" mean that the variable is off limits to other
methods.
I think your additional object idea does capture the semantics very well
(i.e., a method needing state is refactored to a new class where the local
static becomes an object property). We would incorporate that in our
converters, but it's a little too convoluted (it's easier for people to
accept the class variable conversion than a refactoring of their classes).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Jon Skeet [C# MVP]" wrote:
David Anton <Da********@discussions.microsoft.comwrote:
The "static" local variable in VB is not limited to "classic" VB, but is
alive and well in VB.NET also.
There is no C# equivalent. It can be replaced by a class-level instance or
static variable in C# (depending on whether the original method was an
instance or static method), but this doesn't quite capture the usefulness of
the local static variable.

It does, however, *exactly* capture the semantics - as that's what the
VB.NET compiler converts the code into.

Personally I'm glad that C# doesn't have statics. Persistent state
should be a property of types and objects, not methods. Whenever a
method feels like it needs state, consider whether that state is
inherently part of the object, or whether it should be part of a new
class in its own right, which the object has a reference to an instance
of.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 10 '06 #12
David,

Exact, I find it always amazing how some C# users are always bloating that
it is something wrong.

I have seen that it can be a very useful feature.

Moreover I have as well seen that the average VB.Net programmers is more
trying to avoid Global variables than C# ones, with the result that the GC
can do its job better with those VB.Net developers. (In this case from the
static keyword it is opposite, that is why I am always very careful when I
use or advice the static keyword in VB.Net, however it fulfils the behaviour
of the average VB.Net developer to declare variables as late as possible).

Just something I mentioned, and is proven in this thread were is by more
people told to set things global. I would like that C# had better (and
easier) possibilities as in VB.Net to declare things in a method.

Cor
"David Anton" <Da********@discussions.microsoft.comschreef in bericht
news:56**********************************@microsof t.com...
The "static" local variable in VB is not limited to "classic" VB, but is
alive and well in VB.NET also.
There is no C# equivalent. It can be replaced by a class-level instance
or
static variable in C# (depending on whether the original method was an
instance or static method), but this doesn't quite capture the usefulness
of
the local static variable.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Peter Bromberg [C# MVP]" wrote:
>The classic VB "static" keyword and the C# static (and VB.NET "Shared")
modifiers are not the same thing. In classic VB, "static" was used to
retain
the value of a variable inside a function.

Shared and Static in VB.NET and C# respectively mean, when applied to a
variable, that all instances of the object share the same piece of data.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rodchar" wrote:
hey all,
vb has a static keyword for variables, what is charp's
equivalent,please?

static tempVar as String

thanks,
rodchar

Nov 10 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Mertz | last post by:
At the suggestion of one of my correspondents, I slightly reluctantly implemented an RSS feed for my website/writing. It is perhaps a bit crude so far, but maybe I'll spiff it up. The RSS also...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
7
by: Jonathan Fine | last post by:
Giudo has suggested adding optional static typing to Python. (I hope suggested is the correct word.) http://www.artima.com/weblogs/viewpost.jsp?thread=85551 An example of the syntax he proposes...
86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
7
by: ben | last post by:
hello, an algorithm book i'm reading talks about the connectivity problem/algorithm. it gives a number of examples where the connectivity problem applies to real life situations (like, the...
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
11
by: JS | last post by:
In K&R I have found this: static char allocbuf; static char *allocp = allocbuf; But *allocp has not been set to point at anything yet so how is it possible to make the contents of an unknown...
2
by: yaron | last post by:
Hi, for porting java to c# i need to know: What is the C#.NET equivalent for java.net.SocketAddress and java.nio.ByteBuffer ? Thanks.
28
by: gnuist006 | last post by:
I have some code like this: (if (test) (exit) (do something)) or (if (test)
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.