How can I correctly perform functions (content-wise) to give me the result (distance from New York city to MIAMI)?
Firstly, there is no absolutely correct answer, and everyone will have their own opinion. In my opinion, I would suggest adding a new class to your project.
class Formulas { public static double CalculateVelocityFromMileage(double startMileage, double endMileage, double time) { return (endMileage - startMileage) / time; } }
This isolates the logic for computing speed, distance, and average time to a particular place and makes no assumptions about what you call TextBox controls or how the user should enter information in these text fields.
You must make these functions static. You should think of a static function as one that requires only the input provided in the function definition. A static function is good, it does not depend on elements that are hidden from the kind of person calling your function. Of course, for static functions you have no choice but to return to double.
And you must make the function public, so the code in the click event can call it like this:
Formulas.CalculateVelocityFromMileage(start, end, time);
Remember the following:
1. The function should do one thing and do one thing well 2. The function should not rely on hidden values, its output should be based only on its arguments.
You may be able to write a little more code, but you will thank yourself when you start writing more code as your application grows.
But trust your own instincts and find your own style and find out what works for you.