Dean Naysmith
1
Q:

c# global function without class

// No. in c# everything is an object
// Make them static and put them in a static utility class
// This way you can execute a method from any object any time
// Program.cs:
using static Functions;
class Program
{
    static void Main()
    {
        Said("Hello World!");
    }
}
// Functions.cs
public static class Functions
{
    public static void Said(string message) => Console.WriteLine(message);
}
// NOTE: using static {namespace}
0

New to Communities?

Join the community