Connecting Tech Pros Worldwide Help | Site Map

add textbox and button to output to messagebox in C#

  #1  
Old June 21st, 2009, 06:33 AM
Member
 
Join Date: Apr 2007
Posts: 99
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

Last edited by tlhintoq; June 21st, 2009 at 06:55 AM. Reason: [CODE] ... your code here ... [/CODE] tags added
  #2  
Old June 21st, 2009, 06:56 AM
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,691
Provided Answers: 3

re: add textbox and button to output to messagebox in C#


Those are good 'wants'.

Did you have a question for the volunteers here?
  #3  
Old June 21st, 2009, 11:59 AM
Member
 
Join Date: Apr 2007
Posts: 99

re: add textbox and button to output to messagebox in C#


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)
?
  #4  
Old June 21st, 2009, 12:19 PM
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,691
Provided Answers: 3

re: add textbox and button to output to messagebox in C#


Quote:
Originally Posted by buddyr View Post
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)
?
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.

Second:
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)
  5.  
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)
  3.  
  #5  
Old June 21st, 2009, 12:29 PM
Member
 
Join Date: Apr 2007
Posts: 99

re: add textbox and button to output to messagebox in C#


Thank you - same method name with different combination of parameters and/or data types
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating and populating folders in vb.net Bomac8 answers 0 August 13th, 2007 10:00 PM
How to show the progress of the file being downloaded? Martin Ho answers 9 November 20th, 2005 10:28 AM
Acceleration Keys behavies incorrectly BuddyWork answers 1 November 15th, 2005 09:06 PM
Pulling 2 values from 2 textboxes displayed in a third TG answers 1 July 20th, 2005 05:53 AM