global function accessible in whole project asp.net mvc code example

Example 1: how to create public variable in c#

public static class Myvariables{

    public static int x = 1;

}

Example 2: 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}