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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to pass null to a ref bool or out bool parameter?

How to pass null to a ref bool or out bool parameter?

Scheduled Pinned Locked Moved C#
tutorialquestion
8 Posts 6 Posters 1 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
    yyf
    wrote on last edited by
    #1

    Hi, How to pass null to a ref bool or out bool parameter? Thanks.

    C J L 3 Replies Last reply
    0
    • Y yyf

      Hi, How to pass null to a ref bool or out bool parameter? Thanks.

      C Offline
      C Offline
      Charlie Williams
      wrote on last edited by
      #2

      bool is a value type, therefore it cannot be null. bool is either true or false. There is no other state. By the way, when using out, the variable must be assigned a value before the method returns. The value of your variable going in wouldn't matter because it will be assigned a value before you get it back. Passing null (even if you could) wouldn't have any affect. Charlie if(!curlies){ return; }

      P 1 Reply Last reply
      0
      • Y yyf

        Hi, How to pass null to a ref bool or out bool parameter? Thanks.

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        FYI .NET 1.2, set to be beta'd this year and released next year, will utilize 1.2 generics feature for a Nullable value type, defined as Nullable<T>. This would allow you to pass a null value into a value parameter. See here[^] for more info. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

        H 1 Reply Last reply
        0
        • J Judah Gabriel Himango

          FYI .NET 1.2, set to be beta'd this year and released next year, will utilize 1.2 generics feature for a Nullable value type, defined as Nullable<T>. This would allow you to pass a null value into a value parameter. See here[^] for more info. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          It will be .NET 2.0, not 1.2. The file versions are only labeled as 1.2, just like the file versions for 1.1 are 1.1 but the assembly versions are still 1.0.5500.0. ".NET 2.0" is mentioned in many places on Microsoft et. al. sites.

          Microsoft MVP, Visual C# My Articles

          J 1 Reply Last reply
          0
          • H Heath Stewart

            It will be .NET 2.0, not 1.2. The file versions are only labeled as 1.2, just like the file versions for 1.1 are 1.1 but the assembly versions are still 1.0.5500.0. ".NET 2.0" is mentioned in many places on Microsoft et. al. sites.

            Microsoft MVP, Visual C# My Articles

            J Offline
            J Offline
            Judah Gabriel Himango
            wrote on last edited by
            #5

            Oh really? I didn't know that; I knew C# would be C# 2.0, but I was under the impression it was .NET 1.2. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

            H 1 Reply Last reply
            0
            • J Judah Gabriel Himango

              Oh really? I didn't know that; I knew C# would be C# 2.0, but I was under the impression it was .NET 1.2. --------------------------- He who knows that enough is enough will always have enough. -Lao Tsu

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              Here's one current reference: http://msdn.microsoft.com/vstudio/productinfo/roadmap.aspx#2005[^]. I believed they used ".NET 1.2" for a while but that started changing a few months ago. [EDIT] Oh, and rightly so. A LOT (as I'm sure you know) is changing between 1.1 and 2.0, unlikes the few changes between 1.0 and 1.1. It's still mostly backward compatible, but it includes a lot of bug fixes, performance enhancements, control adapters (new way to provide owner-drawing that's truly aweseom!), many new ASP.NET enhancements including some for WSS/SPS, and - of course - generics. [/EDIT]

              Microsoft MVP, Visual C# My Articles

              1 Reply Last reply
              0
              • C Charlie Williams

                bool is a value type, therefore it cannot be null. bool is either true or false. There is no other state. By the way, when using out, the variable must be assigned a value before the method returns. The value of your variable going in wouldn't matter because it will be assigned a value before you get it back. Passing null (even if you could) wouldn't have any affect. Charlie if(!curlies){ return; }

                P Offline
                P Offline
                partyganger
                wrote on last edited by
                #7

                There is some sourceForge project available that does implement just that. Nullable Value types. http://nullabletypes.sourceforge.net/ I wouldn't recommend it (if it's supposed to be a boolean, check for a boolean)

                1 Reply Last reply
                0
                • Y yyf

                  Hi, How to pass null to a ref bool or out bool parameter? Thanks.

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  Try this:

                  void Foo(ref object boolean)
                  {
                  if (boolean == null) //blah blah
                  else
                  {
                  bool value = (bool) boolean;
                  }
                  }

                  top secret

                  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