"John Bailo" <ja*****@texeme.com> wrote in message
news:43**************@texeme.com...
Lambert Symth wrote: How can i use a variable from within a different function in which it was
not set.
Like the example.
using System;
namespace test
{
class class1
{
public string Name=string.empty;
static void Main()
{
string Name = "bob";
start();
}
static void start()
{
Console.WriteLine(Name);
}
}
}
Almost. If you get rid of the double declaration, this would likely work.
Replace this:
string Name = "bob";
with this
Name = "bob";
(I'm guessing that this was your intent.)
Also, the variable could be declared 'private' instead. That would be
better data hiding.
To the OP: the best solution is to pass the variable as a parameter.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--