title: C#: Have a "Optional" Parameter that by default uses the value of a required parameter
body: <p>How can i implement a "optional" parameter to a function such that when <code>endMarker</code> is not given, i will use the value from a required parameter <code>startMarker</code>? i currently use a nullable type and check if <code>endMarker</code> is null i set it to <code>startMarker</code></p>
  
  <pre><code>protected void wrapText(string startMarker, string? endMarker = null) { 
      if (endMarker == null)
          endMarker = startMarker; 
  }
  </code></pre>
  
  <p>but the problem now is i get an error saying it cannot cast <code>string?</code> into <code>string</code></p>
  
  <pre><code>(string)endMarker
  </code></pre>
  
  <p>how can i cast <code>endMarker</code> to a <code>string</code> so i can use it? or is there a better way of implementing this?</p>