add textbox and button to output to messagebox in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buddyr
    New Member
    • Apr 2007
    • 105

    add textbox and button to output to messagebox in C#

    Hello, I have a class firstClass
    Code:
    public static int add(int numberOne, int numberTwo)
    {
        return (numberOne + numberTwo);
    }
    in form two texboxes and a button:
    code for button is:
    Code:
    int total = firstClass.add(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
                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; Jun 21 '09, 05:55 AM. Reason: [CODE] ... your code here ... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Those are good 'wants'.

    Did you have a question for the volunteers here?

    Comment

    • buddyr
      New Member
      • Apr 2007
      • 105

      #3
      to overload the method to allow strings can I use a method like:
      Code:
      public static int add( string stingOne, string stringTwo, stringThree)
      {
      return (int.Parse(stringOne) + int.Parse(stringTwo) + int.Parse(stringThree)
      }
      ?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Originally posted by buddyr
        to overload the method to allow strings can I use a method like:
        Code:
        public static int add( string stingOne, string stringTwo, stringThree)
        {
        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 "
        Code:
        private int CalculateTotal(int nOne)
        private int CalculateTotal(int nOne, nTwo)
        private int CalculateTotal(List<int> nList)
        private int CalculateTotal(Decimal Yogi, float Booboo, string RangerSmith)
        So you tell me... Would these all be valid overloads for your method?
        Code:
        public static int add(string stingOne, string stringTwo, stringThree)
        public static int add(int numberOne, int numberTwo)

        Comment

        • buddyr
          New Member
          • Apr 2007
          • 105

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

          Comment

          Working...