Home > OS >  Dynamic variable do a null result
Dynamic variable do a null result

Time:11-07

im trying to do a dynamic variable and export the variable to another form, i watched every post for this problem but no one worked someone can help me please.

In the settings form:

public string javapath = "javaw.exe";
public int ram = 1024;

private void gunaTrackBar1_ValueChanged(object sender, EventArgs e)
{
    label1.Text = "RAM:  "   gunaTrackBar1.Value   "GB";
    ram = gunaTrackBar1.Value;
}

private void gunaTextBox1_TextChanged(object sender, EventArgs e)
{
    javapath = gunaTextBox1.Text;
    Console.WriteLine(javapath);
}

and the main form:

private void gunaGradientButton1_Click(object sender, EventArgs e)
{
    Settings set = new Settings();
    Console.WriteLine(set.javapath); //where i get a null result
}

CodePudding user response:

You need to provide value for javapath field from set object. So your code should be something like this

private void gunaGradientButton1_Click(object sender, EventArgs e)
{
    Settings set = new Settings();
    //this.javapath is private variable from top of the class
    set.javapath = this.javapath;
    Console.WriteLine(set.javapath);
}

Also highly reccomend you to see C# naming conventions

  •  Tags:  
  • c#
  • Related