Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help: I'm new to C#: I want to make a global function

Help: I'm new to C#: I want to make a global function

Scheduled Pinned Locked Moved C#
csharpsaleshelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheFoZ
    wrote on last edited by
    #1

    Hi As you may be able to tell I am a bit new to C# and I may be attacking this from the wrong angle. I would like to create global function for the program I am writing. I would like to group these functions together for ease i.e. Customer related functions, general function but enable them to be used by other bits of code. I can do this fine in VB.NET but cannot get them to work in C#. For Example I would like a function that returns a string that is stripped of all punctuation and is in upper case. This would be a general function and I would like it in its own code file so I can group it together with other ones. I've had a look in my book and cannot find anything that helps. Is this more of a VB thing and is done differently in C# or am I missing something. ps I'm using C# 2005 Express Edition. Many Thanks

    The FoZ

    J G 2 Replies Last reply
    0
    • T TheFoZ

      Hi As you may be able to tell I am a bit new to C# and I may be attacking this from the wrong angle. I would like to create global function for the program I am writing. I would like to group these functions together for ease i.e. Customer related functions, general function but enable them to be used by other bits of code. I can do this fine in VB.NET but cannot get them to work in C#. For Example I would like a function that returns a string that is stripped of all punctuation and is in upper case. This would be a general function and I would like it in its own code file so I can group it together with other ones. I've had a look in my book and cannot find anything that helps. Is this more of a VB thing and is done differently in C# or am I missing something. ps I'm using C# 2005 Express Edition. Many Thanks

      The FoZ

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Customer-related functions should be instance methods on the Customer class. For things that don't require an instance, make them static. For example,

      public class MyGlobalFuncs
      {
          public static void Foo() { }
      }

      That can be invoked like this: MyGlobalFuncs.Foo()

      Life, family, faith: Give me a visit. From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?" Judah Himango

      T 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Customer-related functions should be instance methods on the Customer class. For things that don't require an instance, make them static. For example,

        public class MyGlobalFuncs
        {
            public static void Foo() { }
        }

        That can be invoked like this: MyGlobalFuncs.Foo()

        Life, family, faith: Give me a visit. From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?" Judah Himango

        T Offline
        T Offline
        TheFoZ
        wrote on last edited by
        #3

        Thanks for that. Its so easy when you know how! Thanks again.

        The FoZ

        1 Reply Last reply
        0
        • T TheFoZ

          Hi As you may be able to tell I am a bit new to C# and I may be attacking this from the wrong angle. I would like to create global function for the program I am writing. I would like to group these functions together for ease i.e. Customer related functions, general function but enable them to be used by other bits of code. I can do this fine in VB.NET but cannot get them to work in C#. For Example I would like a function that returns a string that is stripped of all punctuation and is in upper case. This would be a general function and I would like it in its own code file so I can group it together with other ones. I've had a look in my book and cannot find anything that helps. Is this more of a VB thing and is done differently in C# or am I missing something. ps I'm using C# 2005 Express Edition. Many Thanks

          The FoZ

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          TheFoZ wrote:

          I would like to create global function

          That is not possible. You can use static methods, as Judah suggested, but they are not global.

          TheFoZ wrote:

          I can do this fine in VB.NET

          No, you can't. VB.NET doesn't have any global functions either. If you mean a module, that is just a class where all members automatically become static.

          Despite everything, the person most likely to be fooling you next is yourself.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups