How do I fill a text box with another class value

Posted on 2011-04-22
Last Modified: 2013-12-16
I'm a beginner in C#
I declare a structure in a class named OakSensor.cs

public struct tOakSensor
        [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 24)]
        public string SN;
I try to use the SN value in another class named form3.cs

private void CmdLancer_Click(object sender, EventArgs e)
            tOakSensor sensorxx = new tOakSensor();
            textBox1.Text = (sensorxx.SN);

There is no error message but the textbox remains empty.
Within the OakSensor.cs the line :
        Console.WriteLine("SN:{3}", Sensor.SN);
returns the correct value

Question by:luciepaul
    LVL 43

    Accepted Solution

    You haven't assigned a value to the string SN, hence it uses the (default) value of "".  So everything is working correctly.

    Author Comment

    Actually the line "Console.WriteLine("SN:{3}", Sensor.SN); works well when embedded in  a method:
     public static void Oak_PrintSensorInfo(ref tOakSensor Sensor)
              Console.WriteLine("SN:{3}", Sensor.SN);

    I guess the method gives a value to" sensor" and consequently to SN

    How can I reproduce that in the form3 class ( ie finding the sensor serial number Sensor.SN) ?

    Thanks for helping a real beginner in C#

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now