title: C# Optional Out Parameter
body: <p>Is there any way to make an out parameter of a method optional?  I have a method that needs several parameters to return null most of the time, but sometimes they will have a value.  I am trying to find out if there is a better way to accomplish this than by setting the values to null first, or setting them to null after the if/else.  This may be the only way to do it, but it would be nice if there were optional out parameters or something equivalent.  Here is the code:</p>
  
  <pre><code>    private static void GetInitInfo(string initLine, string ncPointType, out double? relinquishDefault, out bool? ignoreRelinquishDefault, out bool? closedForStart, out bool? adjustDisabled)
      {
          relinquishDefault = null;
          ignoreRelinquishDefault = null;
          closedForStart = null;
          adjustDisabled = null;
  
          switch (ncPointType)
          {
              case "MSD":
                  adjustDisabled = LastToken&lt;bool?&gt;(initLine);
                  break;
              case "BO":
                  relinquishDefault = SecondToken&lt;double&gt;(initLine);
                  closedForStart = ThirdToken&lt;bool?&gt;(initLine);
                  ignoreRelinquishDefault = !ForthToken&lt;bool?&gt;(initLine);//ignoreRelDef would be reverse of use initial value
                  break;
              case "MSO":
                  closedForStart = SecondToken&lt;bool?&gt;(initLine);
                  relinquishDefault = ThirdToken&lt;double&gt;(initLine);
                  ignoreRelinquishDefault = !ForthToken&lt;bool?&gt;(initLine);//ignoreRelDef would be reverse of use initial value
                  break;
              case "AD":
                  relinquishDefault = ThirdToken&lt;double&gt;(initLine);
                  ignoreRelinquishDefault = false;
                  break;
              case "BD":
                  relinquishDefault = SecondToken&lt;double&gt;(initLine);
                  adjustDisabled = LastToken&lt;bool?&gt;(initLine);
                  ignoreRelinquishDefault = false;
                  break;
              case "AOS":
                  relinquishDefault = FirstToken&lt;double&gt;(initLine);
                  ignoreRelinquishDefault = !ThirdToken&lt;bool?&gt;(initLine);//ignoreRelDef would be reverse of use initial value
                  break;
          }
      }
  </code></pre>