By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

C# equivalent of VB "Module"

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
> 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 discussion thread is closed

Replies have been disabled for this discussion.