Been trying to figure out why I am unable to initialize new objects with property values. Probably overlooking something very basic - but can't grasp what it is. Hopefully I can phrase my question in such a way that it will be useful for others as well.
In my Main class I have the following code which calls a custom usercontrol that I have defined in another class.
BallUc ball = new BallUc {
Number = 100
};
MessageBox.Show(ball.Number.ToString()); //this works and returns '100'.
Relevant part of my BallUc code;
private int _number { get; set; }
public int Number{
get { return _number ; }
set { _number = value; }
}
public BallUc() {
InitializeComponent();
MessageBox.Show(this.Number.ToString()); //this doesn't work and returns '0'.
}
I need the number variable to compute some functions in the BallUc class. Hope that my question is clear, if anything needs clarification please let me know. Thank you in advance for your time!