How can I use a variable/const, declared in Main, inside another method?
Without passing it like: static string my_method(string my_variable_to_pass)
Just using static void my_method()
What I want is to call any other method into Main and it has to use the variable declared in Main.
I do not want to use public static class either because it does not seem the proper way. Is there another way?
Here is an example of what I want. This code does not work because "cats does not exist in the current contend" inside test_method(). But how could I make it work without adding too complicated code?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
string cats;
cats = "1000 Cats";
test_method();
cats = "6 Cats";
test_method();
}
static void test_method()
{
Console.Write(cats);
}
}