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. Convert a list element

Convert a list element

Scheduled Pinned Locked Moved C#
questionhelp
6 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.
  • A Offline
    A Offline
    Anka_Ame
    wrote on last edited by
    #1

    Can someone help me telling me how can I convert a element of a list to int?

    P 1 Reply Last reply
    0
    • A Anka_Ame

      Can someone help me telling me how can I convert a element of a list to int?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You could call Convert.ToInt32(listArray[0].ToString());. Alternatively, if you're using .NET 2, I would recommend just creating the List as List<int> list = new List<int>();

      Deja View - the feeling that you've seen this post before.

      D P 2 Replies Last reply
      0
      • P Pete OHanlon

        You could call Convert.ToInt32(listArray[0].ToString());. Alternatively, if you're using .NET 2, I would recommend just creating the List as List<int> list = new List<int>();

        Deja View - the feeling that you've seen this post before.

        D Offline
        D Offline
        DavidNohejl
        wrote on last edited by
        #3

        Pete O`Hanlon wrote:

        call Convert.ToInt32(listArray[0].ToString());

        Is there any reason why you are calling ToString()? Convert works on object too... Only meaningful thing I can think of is to provide IFormatProvider, but then again there is Convert.ToInt32 (Object, IFormatProvider) overload.


        "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

        P 1 Reply Last reply
        0
        • D DavidNohejl

          Pete O`Hanlon wrote:

          call Convert.ToInt32(listArray[0].ToString());

          Is there any reason why you are calling ToString()? Convert works on object too... Only meaningful thing I can think of is to provide IFormatProvider, but then again there is Convert.ToInt32 (Object, IFormatProvider) overload.


          "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          dnh wrote:

          Is there any reason why you are calling ToString()

          Yup - typing in away from a dev box and doing it from memory - I don't tend to use the .NET 1 list anymore.:-D

          Deja View - the feeling that you've seen this post before.

          D 1 Reply Last reply
          0
          • P Pete OHanlon

            dnh wrote:

            Is there any reason why you are calling ToString()

            Yup - typing in away from a dev box and doing it from memory - I don't tend to use the .NET 1 list anymore.:-D

            Deja View - the feeling that you've seen this post before.

            D Offline
            D Offline
            DavidNohejl
            wrote on last edited by
            #5

            :-D


            "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

            1 Reply Last reply
            0
            • P Pete OHanlon

              You could call Convert.ToInt32(listArray[0].ToString());. Alternatively, if you're using .NET 2, I would recommend just creating the List as List<int> list = new List<int>();

              Deja View - the feeling that you've seen this post before.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              If the list is of ints to begin with, only a cast required.

              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