Get Int with TextBox

This is a discussion on Get Int with TextBox within the C# Programming forums, part of the General Programming Boards category; txtA.txt txtB.text lblAnswer = txtA.text + txtB.text If i input 1 and 1 i get 11 or if i input ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    24

    Get Int with TextBox

    txtA.txt
    txtB.text

    lblAnswer = txtA.text + txtB.text

    If i input 1 and 1 i get 11 or if i input 2 and 2 i get 22 how can i add the two numbers as if they were ints and not join them as strings

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    Parse them into ints and add them together, instant string addition. :-)
    Code:
    using System;
    
    class test {
      public static void Main()
      {
        string a = "2", b = "2";
    
        Console.WriteLine(int.Parse(a) + int.Parse(b));  
      }
    }
    *Cela*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21