more G-Labs products

Author Topic: C# public void  (Read 881 times)

March 18, 2015, 01:41:29 AM
Read 881 times

enterprised

  • ****
  • Information
  • Sr. Member
  • Posts: 101
  • Things are only impossible until they are not
Need some help.

I can't get the subroutine code to work in HG C# code app's, see code example below.

Is this by design or should I use something different to create a subroutine?

public void  SomeThing()
   {
             // some code to make something happen which can be called from another bit of code
        }
4a 75 73 74 20 61 20 70 65 72 73 6f 6e 20 68 61 76 69 6e 67 20 66 75 6e 20 77 69 74 68 20 68 6f 6d 65 20 61 75 74 6f 6d 61 74 69 6f 6e
enterprised == guytpetj

March 18, 2015, 11:03:21 AM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
This is by design. HG c# programs are just straight c# coding with no class definition.
To define a subrouting you can do like this:

Code: [Select]
var SomeThing = new Action(()=>{
  Program.Notify("Test", "Hello World!");
});

SomeThing();

or in case you need a return value

Code: [Select]
var GetHalf = new Func<double, double>((number)=>{
  return number / 2d;
});

Program.Notify("Test", "Half of 5 is " + GetHalf(5));


Cheers,
g.