To add to what Ignacio wrote, your entire .NET application cannot see
_that_ string... it can see _those_ strings, because the way you wrote
the declaration, there is a separate string for each instance of Class1
that you create via "new". Therefore, other classes in your .NET
application need to have an instance of Class1 handy in order to
determine which of the many strings named inVoiceNumber they mean:
Class1 a = new Class1();
Class1 b = new Class1();
a.inVoiceNumber is a different string than b.inVoiceNumber.* Whether
this is a good thing or not depends upon what inVoiceNumber is supposed
to hold. If you really do need a different string in there for each
instance of Class1 (in other words, if inVoiceNumber forms part of the
_state_ of a Class1 instance) then you got it right. If, however, there
should be only one inVoiceNumber for the whole application, then you
should declare it with the "static" modifier as Ignacio suggested, at
which point you no longer need to have a particular instance of Class1
handy in order to determine which inVoiceNumber you mean; you can just
say:
Class1.inVoiceNumber
and that gets you the only one there is. Additionally, if inVoiceNumber
never changes, you could declare it "const" and initialize it on the
spot:
const string inVoiceNumber = "1234";
Declaring it "const" automatically means "static", so again there is
only one for your whole application, and you get at it by saying
Class1.inVoiceNumber.
* a.inVoiceNumber is not necessarily, under the covers, a different
string from b.inVoiceNumber because of something that I believe is
called "string folding": to save memory, the CLR will point two
distinct string references at the same memory location if they
"contain" identical strings. However, it's usually better practice to
think of strings held in different string variables, or different
object instances as completely different objects, even though the CLR's
little optimization may make it technically untrue from time to time.