Global Functions in c# (replacement of Module)


  • Is there any replacement of Module feature of VB in C# as I have to declare function that can be directly accessable.
    Thursday, December 02, 2010 7:40 AM


All replies

  • A VB Module is (almost) the same as a C# Static Class

    Be aware that for keeping data in that you are using C# but are not doing that in an OOP way.


    Thursday, December 02, 2010 7:52 AM
  • Thanks Cor:

    I know but want to check it. I need to call the function without the class name, can u help in it plz.

    Thursday, December 02, 2010 8:05 AM
  • Why do you need to call the method without the class name?

    If you really need that, declare the method in the class from which you're calling it.

    Thursday, December 02, 2010 10:51 AM
  • Thanks allot Louisf. but by but my concerns changed.
    Thursday, December 02, 2010 10:59 AM
  • Maybe this reaches your ultimate wish

    Extension methods

    Thursday, December 02, 2010 12:29 PM
  • Thx Cor.
    Friday, December 03, 2010 8:08 AM
  • I have to say that the VB 'feature' of being able to access a method (declared in a VB 'Module') without any qualification is really something that you shouldn't want.  Doesn't this make your code more difficult to understand?  If you have a class by the name of 'Foo', wouldn't you want to indicate this when calling static methods of that class so that people reading your code know instantly where the method is from?

    Convert between VB, C#, C++, & Java (
    Friday, December 03, 2010 4:23 PM
  • David,

    We agree but I've the same with extension methods (for which I should know every method from every class or am only able to see that using the IDE), somehow some people don't want to make good maintainable programs, I've always the idea they are more interested in programs with all kind of mostly senseless coding used.

    My experience is that a good maintainable program is also a good running program.


    Friday, December 03, 2010 6:02 PM
  • I would agree with these other experienced answerers and this is not to demean VB.NET but to illustrate that C# is different and the paradigm is slightly more object oriented.

    John Grove - DSS, Senior Software Engineer
    Friday, December 03, 2010 7:31 PM
  • John,

    With C# you could also make awful non OOP related Static methods which is often done. I would not take this one or the one you mention to judge that C# is more OOP oriented than VB. C# has very much legacy from C++ which got that from C, while it is not even an upgrade of those.

    VB is an already old program language, and like C++ it has many legacy behaviour included. But it is somebodies own responsibility if he uses that in a program. 

    I'm sure that you are not using (know) all the words which can be expressed in English.

    So if somebody wants to use this awful kind of programming in VB, it is his decisions, if he get paid to do afterwards to do the maintenance, he is then lucky.

    In the OOP part there is 100% parity between VB and C#.



    Saturday, December 04, 2010 7:53 AM
  • There may be parity in that VB.NET is object oriented, but the culture still remains to use non object oriented methodologies. Additionally, the My namepspace was introduced in 2005 to "help" the VB6 folks make the transition. Now, you can call up forms without even instantiating them and do other things that are questionable in VB. So, you are right in that it is equally as powerful as C# (almost, not quite), but the culture of VB6 is still prevalent.
    John Grove - DSS, Senior Software Engineer
    Monday, December 06, 2010 5:26 PM