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. string to int, double?

string to int, double?

Scheduled Pinned Locked Moved C#
questioncsharp
5 Posts 5 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.
  • A Offline
    A Offline
    alma
    wrote on last edited by
    #1

    How can i convert a string into an int or double in C#? -Alma-

    M N I L 4 Replies Last reply
    0
    • A alma

      How can i convert a string into an int or double in C#? -Alma-

      M Offline
      M Offline
      mikemilano
      wrote on last edited by
      #2

      string s = "5"; int i = int.Parse(s);

      1 Reply Last reply
      0
      • A alma

        How can i convert a string into an int or double in C#? -Alma-

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        alma wrote: How can i convert a string into an int or double in C#? You may also want to check out the Convert Class[^] and it's members[^] -Nick Parker

        1 Reply Last reply
        0
        • A alma

          How can i convert a string into an int or double in C#? -Alma-

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          you might also want to put it inside a try block also in case it cant be converted. the Char class has an isNumber to determine if thier all numbers. I'm sure theres a better way of doing it though Maybe even better would be to extend the Double if its not final I'm not an expert yet, but I play one at work. Yeah and here too.

          1 Reply Last reply
          0
          • A alma

            How can i convert a string into an int or double in C#? -Alma-

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            hi, there is a simple way of doing this. suppose you have a string "strg" and an int "ix". try { ix = Convert.ToInt32(strg); } catch(Exception ex) // needed in case string cannot be converted. { // do something with the exception } i think you can similarly convert to double as well.

            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