Re: accessing a field of another class within same namespace
- From: "Carlos" <ch_sanin@xxxxxxxxx>
- Date: Wed, 5 Oct 2005 16:20:37 -0400
Thanks Jon,
I instantiated it, but the value which has been assigned does not appear.
What I did was to make it static public, but ideally I would just
like to access it with the value that it has (not globally).
Thanks,
Carlos.
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1dae314496ec018c98c874@xxxxxxxxxxxxxxxxxxxxxxx
> Carlos <ch_sanin@xxxxxxxxx> wrote:
>> I am trying to access a public field of another form class within
>> the same namespace. The field is public
>
> Oh dear - you should consider making it private, backing a public
> property.
>
>> , what is the best way
>> to access it from a different class? I defined as
>> private MyNameSpace.Form1 cForm1;
>>
>> and I am trying to use it later as
>>
>> TextBox.Text = cForm1.TextBox.Text;
>>
>> I see the properties, but I have a warning telling me that cForm1 is
>> never
>> assigned, and that its value will always be null. How can I avoid that?
>
> Simple - give it a value. I think you're missing that you need an
> instance of the form whose field you want to change. You need to ask
> yourself *which* form you want to use the field of. There could be
> several forms of the same type being shown at once (at least
> conceptually).
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: accessing a field of another class within same namespace
- From: Jon Skeet [C# MVP]
- Re: accessing a field of another class within same namespace
- References:
- accessing a field of another class within same namespace
- From: Carlos
- Re: accessing a field of another class within same namespace
- From: Jon Skeet [C# MVP]
- accessing a field of another class within same namespace
- Prev by Date: Re: copy ctore, assignment operator and Clone() - dang!
- Next by Date: Re: Get Messages from another application
- Previous by thread: Re: accessing a field of another class within same namespace
- Next by thread: Re: accessing a field of another class within same namespace
- Index(es):
Relevant Pages
|