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. Converting a nullable type to a non nullable type

Converting a nullable type to a non nullable type

Scheduled Pinned Locked Moved C#
comdata-structuresquestion
6 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.
  • J Offline
    J Offline
    Jeroen De Dauw
    wrote on last edited by
    #1

    Hey, I have a nullable 2d Double array which I want to convert to a non nullable 2d Double array. Is there any sane way of doing this? Cheers!

    Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

    R E 2 Replies Last reply
    0
    • J Jeroen De Dauw

      Hey, I have a nullable 2d Double array which I want to convert to a non nullable 2d Double array. Is there any sane way of doing this? Cheers!

      Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      By nullable 2d array, I presume you mean an array containing double?s. So you want to convert double?[] to double[]... What happens if there is a null in there then?

      Regards, Rob Philpott.

      J 1 Reply Last reply
      0
      • J Jeroen De Dauw

        Hey, I have a nullable 2d Double array which I want to convert to a non nullable 2d Double array. Is there any sane way of doing this? Cheers!

        Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

        E Offline
        E Offline
        Eric Dahlvang
        wrote on last edited by
        #3
                var nullableDoubles = new double?\[2\]\[\];
                nullableDoubles\[1\] = new double?\[\]{null, 1.1, null, 1.2};
        
                double\[\]\[\] nonNullableDoubles = nullableDoubles.Select(doubleArray=>{
                        if(doubleArray==null)
                            return null;
                        else
                           return doubleArray.Where(doubleValue => doubleValue.HasValue).Cast<double>().ToArray();}).ToArray();
        

        --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        J 1 Reply Last reply
        0
        • R Rob Philpott

          By nullable 2d array, I presume you mean an array containing double?s. So you want to convert double?[] to double[]... What happens if there is a null in there then?

          Regards, Rob Philpott.

          J Offline
          J Offline
          Jeroen De Dauw
          wrote on last edited by
          #4

          At the point where I want to convert from nullable to non nullable, there are no null values. I indeed mean Double?[,];

          Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

          1 Reply Last reply
          0
          • E Eric Dahlvang
                    var nullableDoubles = new double?\[2\]\[\];
                    nullableDoubles\[1\] = new double?\[\]{null, 1.1, null, 1.2};
            
                    double\[\]\[\] nonNullableDoubles = nullableDoubles.Select(doubleArray=>{
                            if(doubleArray==null)
                                return null;
                            else
                               return doubleArray.Where(doubleValue => doubleValue.HasValue).Cast<double>().ToArray();}).ToArray();
            

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            J Offline
            J Offline
            Jeroen De Dauw
            wrote on last edited by
            #5

            Hey, Since I'm getting an error saying that 'double?[*,*]' does not contain a definition for 'select', I'm assuming I need to import some namespace. Which one? :) Cheers!

            Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

            E 1 Reply Last reply
            0
            • J Jeroen De Dauw

              Hey, Since I'm getting an error saying that 'double?[*,*]' does not contain a definition for 'select', I'm assuming I need to import some namespace. Which one? :) Cheers!

              Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

              E Offline
              E Offline
              Eric Dahlvang
              wrote on last edited by
              #6

              System.Linq

              --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

              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