Answers for "c# global function without class"

C#
1

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}
Posted by: Guest on August-26-2020

C# Answers by Framework

Browse Popular Code Answers by Language