hey all,
vb has a static keyword for variables, what is charp's equivalent,plea se?
static tempVar as String
thanks,
rodchar 12 2275
rodchar wrote:
hey all,
vb has a static keyword for variables, what is charp's equivalent,plea se?
static tempVar as String
also static in C#
as in:
static string tempVar;
Arne
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,plea se?
static tempVar as String
thanks,
rodchar
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,plea se?
static tempVar as String
thanks,
rodchar
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
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
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
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,plea se?
static tempVar as String
thanks,
rodchar
David Anton <Da********@dis cussions.micros oft.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.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Arne Vajhøj" <ar**@vajhoej.d kwrote in message
news:45******** *************** @news.sunsite.d k...
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 has an HTML
front to it.
If you want to see the latest news about my _Charming Python_ or _XML
Matters_ columns, or about other articles (later, perhaps stuff about
my book), take a look at:
http://gnosis.cx/rss.xml
|
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 FRICKIN'
COOL!!! ***MAN*** that would save me a buttload of work and make my life
sooooo much easier!"
As opposed to minor differences of this feature here, that feature there.
Variations on style are of no interest to me. I'm coming at this from a...
|
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 "help", "copyright", "credits" or "license" for more information.
>>> d1 = {'a':1}
>>> d2 = {'b':2}
>>> d3 = {'c':3}
|
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 is:
> def f(this:that=other):
> print this
This means that f() has a 'this' parameter, of type 'that'.
And 'other' is the default value.
|
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: http://www.clagnut.com/blog/348/
I hope that's going to be a good discussion!
Michael
| |
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 objects may represent computers in a
large network and the pairs represent connections between them)
another real situation example that's given is:
|
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 standard doesn't even care what a normal char
is (because signed and unsigned have equal behavior).
For example if someone does this:
unsigned char a = -2; /* or = 254 */
|
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 address be "allocbuf"??
JS
|
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.
|
by: gnuist006 |
last post by:
I have some code like this:
(if (test)
(exit)
(do something))
or
(if (test)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |