Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to take integer input in c#

how to take integer input in c#

Scheduled Pinned Locked Moved C#
csharptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yuwraj
    wrote on last edited by
    #1

    :( Hi Guies, How to read integer from keyboard in C#. Thanks in Advance...

    D C 2 Replies Last reply
    0
    • Y Yuwraj

      :( Hi Guies, How to read integer from keyboard in C#. Thanks in Advance...

      D Offline
      D Offline
      Divyang Mithaiwala
      wrote on last edited by
      #2

      For console programing you hava to use using System.Console.; & then use ch = System.Console.Read(); //return charater Or str = System.Console.ReadLine(); //return string Divyang Mithaiwala with Best Regards

      Y 1 Reply Last reply
      0
      • D Divyang Mithaiwala

        For console programing you hava to use using System.Console.; & then use ch = System.Console.Read(); //return charater Or str = System.Console.ReadLine(); //return string Divyang Mithaiwala with Best Regards

        Y Offline
        Y Offline
        Yuwraj
        wrote on last edited by
        #3

        I want to take integer value and not char or string. Actually System.Console.Read() reads kay pressed and not int. :(

        C 1 Reply Last reply
        0
        • Y Yuwraj

          I want to take integer value and not char or string. Actually System.Console.Read() reads kay pressed and not int. :(

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Then use int.Parse() to convert it. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

          1 Reply Last reply
          0
          • Y Yuwraj

            :( Hi Guies, How to read integer from keyboard in C#. Thanks in Advance...

            C Offline
            C Offline
            CodyGen
            wrote on last edited by
            #5

            if you are trying to accept only numeric values in your text box, you can use the e.Handle = true of KeyPressEventArgs to cancel the keypress event. You can try the code below. string strnum = "0123456789"; if (strnum.IndexOf(e.KeyChar.ToString())<0) { e.Handled = true; }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups