469,281 Members | 2,481 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

add textbox and button to output to messagebox in C#

107 100+
Hello, I have a class firstClass
Expand|Select|Wrap|Line Numbers
  1. public static int add(int numberOne, int numberTwo)
  2. {
  3.     return (numberOne + numberTwo);
  4. }
in form two texboxes and a button:
code for button is:
Expand|Select|Wrap|Line Numbers
  1. int total = firstClass.add(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
  2.             MessageBox.Show(total.ToString());
I want to overload the method and allow strings instead of integers.
last I want to create another button and diplay in messagebox based on a third textbox.
thank you
Jun 21 '09 #1
4 8174
3,525 Expert 2GB
Those are good 'wants'.

Did you have a question for the volunteers here?
Jun 21 '09 #2
107 100+
to overload the method to allow strings can I use a method like:
Expand|Select|Wrap|Line Numbers
  1. public static int add( string stingOne, string stringTwo, stringThree)
  2. {
  3. return (int.Parse(stringOne) + int.Parse(stringTwo) + int.Parse(stringThree)
Jun 21 '09 #3
3,525 Expert 2GB
Two part reply:
First: Don't be afraid to experiment. It takes 30 seconds to actually put that code in the program and try it. Writting it up for a forum then waiting on a reply is hours. Trial and error will teach you a lot more than someone giving you the yes/no answer.

Overloading is the technique of creating two methods of the same name with different parameter signatures.

These would all be valid signature overloads for a method called "CalculateTotal"
Expand|Select|Wrap|Line Numbers
  1. private int CalculateTotal(int nOne)
  2. private int CalculateTotal(int nOne, nTwo)
  3. private int CalculateTotal(List<int> nList)
  4. private int CalculateTotal(Decimal Yogi, float Booboo, string RangerSmith)
So you tell me... Would these all be valid overloads for your method?
Expand|Select|Wrap|Line Numbers
  1. public static int add(string stingOne, string stringTwo, stringThree)
  2. public static int add(int numberOne, int numberTwo)
Jun 21 '09 #4
107 100+
Thank you - same method name with different combination of parameters and/or data types
Jun 21 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by trint | last post: by
1 post views Thread by rn5a | last post: by
5 posts views Thread by kimiraikkonen | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.