473,397 Members | 2,028 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,397 software developers and data experts.

C# equivalent of VB "Module"

BH
Hi

what would be the C# equivalent of a VB.NET file that looks like this:

Module Utilities

Public Sub UtilitySubOne ( ByVal arg As String)
// blah blah
End Sub

Public Sub UtilitySubTwo ( ByVal arg As String)
// blah blah
End Sub

End Module

....VB.NET has the concept of a 'Module' where you can create a pile of
generally available calls, but I'm not sure how this 'Module' file idea
translates to C#.

Any help appreciated,

BH
Nov 15 '05 #1
5 15407
Hi BH,

It would look something like this:

sealed class Utilities
{
private Utilities(){}

public static void UtilitySubOne(string arg)
{
// blah blah
}

...
}

In other words, VB modules are implemented as sealed classes with a
private constructor where all the members are static. I think that VB also
promotes the member names into the global namespace, which means you can
type:

...
UtilitySubOne("foo")
...

instead of:

...
Utilities.UtilitySubOne("foo")
...

The former isn't something you can do in C#.

Regards,
Dan

"BH" <bo*****@yahoo.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Hi

what would be the C# equivalent of a VB.NET file that looks like this:

Module Utilities

Public Sub UtilitySubOne ( ByVal arg As String)
// blah blah
End Sub

Public Sub UtilitySubTwo ( ByVal arg As String)
// blah blah
End Sub

End Module

...VB.NET has the concept of a 'Module' where you can create a pile of
generally available calls, but I'm not sure how this 'Module' file idea
translates to C#.

Any help appreciated,

BH

Nov 15 '05 #2
The module concept is just a hack put in to make it easier for VB6 users to
migrate to dot net. It goes against the grain of .NET programming in
general; it's really idiosyncratic to VB. So I wouldn't worry to much about
it.

Chris

"BH" <bo*****@yahoo.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Hi

what would be the C# equivalent of a VB.NET file that looks like this:

Module Utilities

Public Sub UtilitySubOne ( ByVal arg As String)
// blah blah
End Sub

Public Sub UtilitySubTwo ( ByVal arg As String)
// blah blah
End Sub

End Module

...VB.NET has the concept of a 'Module' where you can create a pile of
generally available calls, but I'm not sure how this 'Module' file idea
translates to C#.

Any help appreciated,

BH

Nov 15 '05 #3
Cmon Chris...that's not true. All a module is is a specific class...so you
don't have to re-invent it each time you need to use one. One advantage
they have is that they can be referenced without a direct reference which
can make your code a little more concise. Not a huge benefit by any means
but noteworthy nonetheless.

If they really went against everything .NET...why does a single instance
sealed class with all static members have IL that's a dead ringer for a
Module's IL?
"Chris Capel" <ch***@ibanktech.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
The module concept is just a hack put in to make it easier for VB6 users to migrate to dot net. It goes against the grain of .NET programming in
general; it's really idiosyncratic to VB. So I wouldn't worry to much about it.

Chris

"BH" <bo*****@yahoo.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Hi

what would be the C# equivalent of a VB.NET file that looks like this:

Module Utilities

Public Sub UtilitySubOne ( ByVal arg As String)
// blah blah
End Sub

Public Sub UtilitySubTwo ( ByVal arg As String)
// blah blah
End Sub

End Module

...VB.NET has the concept of a 'Module' where you can create a pile of
generally available calls, but I'm not sure how this 'Module' file idea
translates to C#.

Any help appreciated,

BH


Nov 15 '05 #4
Daniel's class shows this very clearly, but all a module is is a Sealed
class with all static members
"BH" <bo*****@yahoo.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Hi

what would be the C# equivalent of a VB.NET file that looks like this:

Module Utilities

Public Sub UtilitySubOne ( ByVal arg As String)
// blah blah
End Sub

Public Sub UtilitySubTwo ( ByVal arg As String)
// blah blah
End Sub

End Module

...VB.NET has the concept of a 'Module' where you can create a pile of
generally available calls, but I'm not sure how this 'Module' file idea
translates to C#.

Any help appreciated,

BH

Nov 15 '05 #5
> One advantage
they have is that they can be referenced without a direct reference which
can make your code a little more concise. Not a huge benefit by any means
but noteworthy nonetheless.


That's the only benefit they offer against the sealed class, static method
C# equivalent, you're right. And as far as VB modules are only the
equivalent of the C# version, they don't go against .NET philosophy. All I
meant was: since you don't have to use the name of the class, it seems
Modules are just a syntactical simulation of global functions. And global
functions are definately soooo three years ago.

:-)

Chris
Nov 15 '05 #6

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

Similar topics

19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
2
by: tedsuzman | last post by:
----- def f(): ret = 2 exec "ret += 10" return ret print f() ----- The above prints '12', as expected. However,
5
by: Jan Danielsson | last post by:
Hello all, I have written a simple whiteboard application. In my application, I want to be able to set draw attributes. This part works. I have a dictionary object which contains stuff like:...
5
by: Bob | last post by:
Are they different names for the same concept ?
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: Shehryar | last post by:
AOA, I urgently want to know the major difference between "Module" and a "Class Module". Plz, reply me as early as possible. Thanx!
14
by: Ivan Voras | last post by:
Hi, I'm looking for a construct that's similar to (Turbo) Pascal's "with" statement. I read about the Python's new "with" statement, but I was dissapointed to learn that it does something...
5
by: Verde | last post by:
I'm learning about .NET assemblies and in the documentation there is mention of "module" or "modules" within an assembly. For example, the Assembly class has a GetModules method. What is a...
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...
0
marktang
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,...
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...
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,...
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...

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.