I've made some changes but I wasn't able to get any bugs out of it (props to you) even by trying to hijack variable values in debug mode so ez pz.
I know this is a practice project but ideally your form elements, text boxes, buttons etc, should have some kind of strict naming convention to make them easier to reference in code:
stackoverflow.com/questions/1246546/best...i-naming-conventions
Also, C# is x10 easier when you use objects. I've made some changes to your solution and uploaded it to my
Google Drive. For example, I set up a BaseItem object that holds all properties that can be shared across anything in ZARP, i.e. price, name etc. (Yes I too spotted the difference in property type in the comment as I uploaded this)
Then you can create a class that inherits from the BaseItem object (inheritance is OP, learn it) like below and plug in any properties that are specific to that object, i.e. nuke detonation time:
Here are my changes to your button click event:
To summarise my changes: I made your event more 'OOP', using objects rather than straight variables in your method or wonky fields in your Form1 class definition.
I added validation after casting the input values for the SCU/Nuke price, validation is never bad so always remember to have it. In this case, Convert.To returns null if the cast fails for whatever reason, which is OK, .ToString() would throw an exception if it failed during cast at runtime.
A couple key things that are handy when working with newer versions of the .NET framework:
- Ternary opertator ( ?: ), a handy way of putting an if-else statement on one line, syntactically it is (expression) ? value if true : value if false
- String interpolation ($""), much more efficient when formatting a string with values, string.Format() is also good. Try to avoid using multiple this +'s in a strange as too many becomes very inefficient.