-1

I have the following classes:

public class Coordinates
{
    public double x;
    public double y;

}

public class WaferAlignment
{
     public Coordinates upper1 { get; set; }
     public Coordinates upper2 { get; set; }
}

And here's part of my code:

   public partial class MainWindow : Window
    {
       WaferAlignment calc = new WaferAlignment();

        public MainWindow()
        {
            InitializeComponent();  
        }

        public void ButtonCalculate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                calc.lower1.x = Convert.ToDouble(Lower_X_TextBox0.Text);
                calc.lower1.y = Convert.ToDouble(Lower_Y_TextBox0.Text);
            }
        }

I've been getting a "Object Reference Not Set to an Instance of an Object" error and I'm almost certain it has to do with me not being able to instantiate Coordinates. I just don't know how or where I should do it. Please understand I'm still a bit new with this and I'd appreciate any guidance.

Lourdea
  • 1
  • 1

1 Answers1

2

You need to initialize upper1 and upper2.

public class WaferAlignment
{
     public Coordinates upper1 { get; set; } = new Coordinates();
     public Coordinates upper2 { get; set; } = new Coordinates();
}
Mike Mozhaev
  • 2,367
  • 14
  • 13