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. Data type conversions problem

Data type conversions problem

Scheduled Pinned Locked Moved C#
csharpasp-netdata-structureshelp
4 Posts 3 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.
  • M Offline
    M Offline
    Michael101
    wrote on last edited by
    #1

    I have an C# ASP.NET web page. I have this conversion problem with my string array to my session variable. string[] stModArray = (string[])Session["modArray"]; Any suggestions...... Thanks in advance!! Michael

    M C 2 Replies Last reply
    0
    • M Michael101

      I have an C# ASP.NET web page. I have this conversion problem with my string array to my session variable. string[] stModArray = (string[])Session["modArray"]; Any suggestions...... Thanks in advance!! Michael

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, As the Session["modArray"] is only returning a string or null you can not cast it directly to string[]. You would have to create an string[] instance and add the result string to the array (at the index you would like it to be). To make it dynamic, you caould use a System.Collections.Specialized.StringCollection (with the "add" method) instead of string[]. P.S.: allways make a !=null check. Hope it helps! All the best, Martin

      1 Reply Last reply
      0
      • M Michael101

        I have an C# ASP.NET web page. I have this conversion problem with my string array to my session variable. string[] stModArray = (string[])Session["modArray"]; Any suggestions...... Thanks in advance!! Michael

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Do this: object o = Session["modArray"]; and check in the debugger to see what's actually stored there. If it's not a string[], you can't turn it into one, at least not like this.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        M 1 Reply Last reply
        0
        • C Christian Graus

          Do this: object o = Session["modArray"]; and check in the debugger to see what's actually stored there. If it's not a string[], you can't turn it into one, at least not like this.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          M Offline
          M Offline
          Michael101
          wrote on last edited by
          #4

          Ok, what I have in this variable are three primary key numbers, so what's getting stored is an int. But the reason why I'm using a string is because I need to return the length for my for loop so the user can cycle backwards and forward viewing each record. -> There are no nulls getting passed in, what's getting passed in is correct. This is the snippart of the code that I'm using to try and do what I've just explaned. Once again since I'm I using a loop, objects and such don't have the length function :'( private void nextMod() { string[] stModArray = (string[])Session["modArray"]; for (int i=0; i

          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