473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

static methods

Is that true you can't have a static method in VB.NET?
Public Static Sub Initialize() -- ???

thanks
Mark
Mar 21 '06 #1
11 44511
You use the keyword 'Shared', but it has the same effect.

So you can have a static method, there is just no static keyword that you
can put in the function declaration.

"Mark" <Ma**@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
Is that true you can't have a static method in VB.NET?
Public Static Sub Initialize() -- ???

thanks
Mark

Mar 21 '06 #2
Mark,

Visual basic had not to do with old legacy names from C.

Therefore is there a name used which describes this better.

Public Shared Sub etc.

I hope this helps,

Cor

"Mark" <Ma**@discussions.microsoft.com> schreef in bericht
news:A7**********************************@microsof t.com...
Is that true you can't have a static method in VB.NET?
Public Static Sub Initialize() -- ???

thanks
Mark

Mar 21 '06 #3
Thanks!

Mark

"Cor Ligthert [MVP]" wrote:
Mark,

Visual basic had not to do with old legacy names from C.

Therefore is there a name used which describes this better.

Public Shared Sub etc.

I hope this helps,

Cor

"Mark" <Ma**@discussions.microsoft.com> schreef in bericht
news:A7**********************************@microsof t.com...
Is that true you can't have a static method in VB.NET?
Public Static Sub Initialize() -- ???

thanks
Mark


Mar 21 '06 #4
dgk
On Tue, 21 Mar 2006 16:30:49 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Mark,

Visual basic had not to do with old legacy names from C.

Therefore is there a name used which describes this better.

Public Shared Sub etc.

I hope this helps,

Cor

I think that you can't declare a class as shared, but if everything in
it is shared then the class is, in reality, shared. Please correct me
if I'm wrong on this.
Mar 21 '06 #5

"dgk" <dg*@somewhere.com> wrote in message
news:o5********************************@4ax.com...
On Tue, 21 Mar 2006 16:30:49 +0100, "Cor Ligthert [MVP]"
<no************@planet.nl> wrote:
Mark,

Visual basic had not to do with old legacy names from C.

Therefore is there a name used which describes this better.

Public Shared Sub etc.

I hope this helps,

Cor

I think that you can't declare a class as shared, but if everything in
it is shared then the class is, in reality, shared. Please correct me
if I'm wrong on this.


Well, in VB, you can...use Module...which, in turn, is a static class :)

Mythran

Mar 21 '06 #6
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
Visual basic had not to do with old legacy names from C.


Well said -- that's why we have our old BASIC legacy 'Static' :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Mar 21 '06 #7
Mythran,
| Well, in VB, you can...use Module...which, in turn, is a static class :)
Unfortunately a Module has the added "annoyance"/"feature" of being
implicitly imported, where as C#'s static class needs to be explicitly
qualified.

If you like the convenience of implicit imported, then using a Module for a
static class is good, however I find needing to qualify the identifiers of a
static class to be more beneficial. As I then know where the identifier is
coming from.

For example:

Debug.WriteLine(...)

You know that the WriteLine is part of the Debug class, rather then:

WriteLine(...)

You don't know if WriteLine is part of System.Diagnostics.Debug,
System.Console, a base class, a Module, or something else...

I normally reserve Module's for truly global identifiers, such as math
functions. I see some benefit in having System.Math being a module, however
its easy enough to import System.Math to gain unqualified access to its
identifiers...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
|
| "dgk" <dg*@somewhere.com> wrote in message
| news:o5********************************@4ax.com...
| > On Tue, 21 Mar 2006 16:30:49 +0100, "Cor Ligthert [MVP]"
| > <no************@planet.nl> wrote:
| >
| >>Mark,
| >>
| >>Visual basic had not to do with old legacy names from C.
| >>
| >>Therefore is there a name used which describes this better.
| >>
| >>Public Shared Sub etc.
| >>
| >>I hope this helps,
| >>
| >>Cor
| >>
| > I think that you can't declare a class as shared, but if everything in
| > it is shared then the class is, in reality, shared. Please correct me
| > if I'm wrong on this.
|
| Well, in VB, you can...use Module...which, in turn, is a static class :)
|
| Mythran
|
Mar 22 '06 #8
dgk
On Wed, 22 Mar 2006 07:06:34 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************@tsbradley.net> wrote:
Mythran,
| Well, in VB, you can...use Module...which, in turn, is a static class :)
Unfortunately a Module has the added "annoyance"/"feature" of being
implicitly imported, where as C#'s static class needs to be explicitly
qualified.

If you like the convenience of implicit imported, then using a Module for a
static class is good, however I find needing to qualify the identifiers of a
static class to be more beneficial. As I then know where the identifier is
coming from.

For example:

Debug.WriteLine(...)

You know that the WriteLine is part of the Debug class, rather then:

WriteLine(...)

You don't know if WriteLine is part of System.Diagnostics.Debug,
System.Console, a base class, a Module, or something else...

I normally reserve Module's for truly global identifiers, such as math
functions. I see some benefit in having System.Math being a module, however
its easy enough to import System.Math to gain unqualified access to its
identifiers...


Then using Imports is bad because you don't know where the
object/method/whatever is actually coming from. And that's true.
Whenever I start playing with someone else's code I start commenting
out the Imports. I love seeing those little blue squigglies appear.
Mar 22 '06 #9
| Then using Imports is bad because you don't know where the
| object/method/whatever is actually coming from. And that's true.
Yes Imports "hide" where identifiers are coming from...

However! You at least need to explicitly list the Imports at the top of each
source file, or at the project level. Whereas a Module is implicitly
imported at the project level...

Project level imports & now project level import aliases can also be both
good & "bad".
Generally I find:
| > Debug.WriteLine(...)

To be easier to read then:

| > System.Diagnostics.Debug.WriteLine(...)
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"dgk" <dg*@somewhere.com> wrote in message
news:cn********************************@4ax.com...
| On Wed, 22 Mar 2006 07:06:34 -0600, "Jay B. Harlow [MVP - Outlook]"
| <Ja************@tsbradley.net> wrote:
|
| >Mythran,
| >| Well, in VB, you can...use Module...which, in turn, is a static class
:)
| >Unfortunately a Module has the added "annoyance"/"feature" of being
| >implicitly imported, where as C#'s static class needs to be explicitly
| >qualified.
| >
| >If you like the convenience of implicit imported, then using a Module for
a
| >static class is good, however I find needing to qualify the identifiers
of a
| >static class to be more beneficial. As I then know where the identifier
is
| >coming from.
| >
| >For example:
| >
| > Debug.WriteLine(...)
| >
| >You know that the WriteLine is part of the Debug class, rather then:
| >
| > WriteLine(...)
| >
| >You don't know if WriteLine is part of System.Diagnostics.Debug,
| >System.Console, a base class, a Module, or something else...
| >
| >I normally reserve Module's for truly global identifiers, such as math
| >functions. I see some benefit in having System.Math being a module,
however
| >its easy enough to import System.Math to gain unqualified access to its
| >identifiers...
|
| Then using Imports is bad because you don't know where the
| object/method/whatever is actually coming from. And that's true.
| Whenever I start playing with someone else's code I start commenting
| out the Imports. I love seeing those little blue squigglies appear.
Mar 23 '06 #10
dgk,

You would than in my opinion be consequent and remove as well all imports
from the project property file.

Would be a very strange looking program than.

In version 2003
Select project properties and look than to imports

Just my thought,

Cor

"dgk" <dg*@somewhere.com> schreef in bericht
news:cn********************************@4ax.com...
On Wed, 22 Mar 2006 07:06:34 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************@tsbradley.net> wrote:
Mythran,
| Well, in VB, you can...use Module...which, in turn, is a static class :)
Unfortunately a Module has the added "annoyance"/"feature" of being
implicitly imported, where as C#'s static class needs to be explicitly
qualified.

If you like the convenience of implicit imported, then using a Module for
a
static class is good, however I find needing to qualify the identifiers of
a
static class to be more beneficial. As I then know where the identifier is
coming from.

For example:

Debug.WriteLine(...)

You know that the WriteLine is part of the Debug class, rather then:

WriteLine(...)

You don't know if WriteLine is part of System.Diagnostics.Debug,
System.Console, a base class, a Module, or something else...

I normally reserve Module's for truly global identifiers, such as math
functions. I see some benefit in having System.Math being a module,
however
its easy enough to import System.Math to gain unqualified access to its
identifiers...


Then using Imports is bad because you don't know where the
object/method/whatever is actually coming from. And that's true.
Whenever I start playing with someone else's code I start commenting
out the Imports. I love seeing those little blue squigglies appear.

Mar 23 '06 #11
I should add to my previous day's post, that the likely hood (at least in my
code) of "overloading" an method is greater then "overloading" a type.

For example there would probably be only a single "Debug" type in my
application (solution) (across all namespaces), where as there maybe many
"Write" methods unique to any numbers of types. (for example Equals,
ToString). <sidenote> I use namespaces more for organization then to allow
me to have 2 types with the same name in different namespaces, as chances
are if they have the same name they have the same function... However this
is not always true, for example the Person domain object and the Person web
page or Person windows form, although I normally use Person, PersonPage &
PersonForm for the types themselves...</sidenote>

Hence qualifying a method with a type name (Debug.WriteLine) is generally
more beneficial then qualifying a type name with a namespace
(System.Diagnostics.Debug)... The Imports System.Diagnostics (at either the
file or project level) simply saves typing System.Diagnostics every place I
need to use the Debug type.

While the qualifying Debug ensures that I can introduce a WriteLine method
in my type without it interfering with calling the Debug.WriteLine method...

For a "better" example of the problems the implicit import causes try
calling VB.Left (Microsoft.VisualBasic.Strings.Left) function in a form.
Because Form has a Left property you cannot call the Left function
unqualified... <sidenote>This is one place where I will use an import alias.
"Imports VB = Microsoft.VisualBasic" which allows me to call
VB.Left...</sidenote>

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"dgk" <dg*@somewhere.com> wrote in message
news:cn********************************@4ax.com...
| On Wed, 22 Mar 2006 07:06:34 -0600, "Jay B. Harlow [MVP - Outlook]"
| <Ja************@tsbradley.net> wrote:
|
| >Mythran,
| >| Well, in VB, you can...use Module...which, in turn, is a static class
:)
| >Unfortunately a Module has the added "annoyance"/"feature" of being
| >implicitly imported, where as C#'s static class needs to be explicitly
| >qualified.
| >
| >If you like the convenience of implicit imported, then using a Module for
a
| >static class is good, however I find needing to qualify the identifiers
of a
| >static class to be more beneficial. As I then know where the identifier
is
| >coming from.
| >
| >For example:
| >
| > Debug.WriteLine(...)
| >
| >You know that the WriteLine is part of the Debug class, rather then:
| >
| > WriteLine(...)
| >
| >You don't know if WriteLine is part of System.Diagnostics.Debug,
| >System.Console, a base class, a Module, or something else...
| >
| >I normally reserve Module's for truly global identifiers, such as math
| >functions. I see some benefit in having System.Math being a module,
however
| >its easy enough to import System.Math to gain unqualified access to its
| >identifiers...
|
| Then using Imports is bad because you don't know where the
| object/method/whatever is actually coming from. And that's true.
| Whenever I start playing with someone else's code I start commenting
| out the Imports. I love seeing those little blue squigglies appear.
Mar 24 '06 #12

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

Similar topics

13
by: Axehelm | last post by:
Okay, I'm in a debate over whether or not static methods are a good idea in a general domain class. I'm personally not a fan of static methods but we seem to be using them to load an object. ...
3
by: Steven D'Aprano | last post by:
I've been doing a lot of reading about static methods in Python, and I'm not exactly sure what they are useful for or why they were introduced. Here is a typical description of them, this one...
8
by: Steven Livingstone | last post by:
Anyone able to explain to me why you cannot define an interface that can then be implemented using static methods? I understand the C# CLS states this, but just interested in the reasons behind...
3
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
5
by: blah, blah, blah | last post by:
I'm developing a .Net web application and created many helper classes often using static (shared in VB.Net) methods. Do I need to use the lock (SyncLock) statement in these methods to prevent...
4
by: Joe Fallon | last post by:
In another post Kevin Spencer stated: "one should be careful of using static fields, properties, and methods, by understanding what the implications of such are (e.g. locking static variables when...
2
by: Ĺženol Akbulak | last post by:
Hi; I am developing an 3 tiered application. And my user interface is an ASP.NET web application. My methods in BLL only uses own parameters and DAL. Now my methods are not static. I heard that...
15
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data...
6
by: MSDNAndi | last post by:
Hi, I have a baseclass (non-static) with some static and some non-static methods/fields/properties. In the baseclass in one of the static methods I need to do something like " somelogic...
12
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
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,...

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.