This is a very vague question, and it probably shows a lack of understanding of how C# works.
There are four types of variables in C#: local, class, parameter, and static and how you would "share" them differs.
Local variables are declared within a method, and exist only for the duration of that method: when the method is called the variables are created, when it
return
s they are destroyed. They have no existence at all outside the body of the method, and can only be "shared" by passing them as a parameter to another method by calling it within the body:
void Foo()
{
string inp = Console.ReadLine();
Bar(inp);
}
Parameter variables are similar to local variables in that they only exist while the method is running, but there value is "shared" by being passed into the method when it is called:
void Bar(string str)
{
Console.WriteLine($"I was passed \"{str}\" when I was called");
}
...
string inp = Console.ReadLine();
Bar(inp)
Class variables are declared outside a method, and are available to all non-static methods in the class (and sometimes other classes depending on the class access modifier). The difference is that they are specific to a particular instance of the class, in the same way that a glove box is specific to a particular car: if you put your mobile in the glove box of your car than come for a drive in my car you don't expect to find your mobile in the glove box!
A class variable is effectively shared by all instance methods automatically:
private string inp = "Not assigned yet";
void Foo()
{
inp = Console.ReadLine();
Bar();
}
void Bar()
{
Console.WriteLine($"I can access \"{str}\" here as well.");
}
Static variables are different: there is only one variable which is "shared" by all code which accesses the class - they are not related to a specific instance and any change to the variable can be seen in all methods regardless of which instance it might be.
That doesn't mean you should use them: I very rarely need a static variable! If the glovebox was
static
then your mobile would be accessible via any car's glovebox: so the chances are that it would have been stolen, or used, or broken within seconds of you putting it in the box because any driver would find it in his glovebox. They aren't a good way to "share" information within a program unless that reflects the "real-world" situation as the value can be changed from any or all instances and that can cause some real headaches!