title: C# Get URI Segments by name
body: <p>Is there any way to get the Segment of a URI using its name?</p>
  
  <p>For example if I have the template:</p>
  
  <pre><code>http://myapi.com/v1/players/{country}
  </code></pre>
  
  <p>How could I extract the value of <code>{country}</code> once it has been matched using <code>UriTemplateMatch</code>?</p>
  
  <p>I have <a href="https://msdn.microsoft.com/en-us/library/system.uri.segments(v=vs.110).aspx" rel="nofollow">read the docs for the class</a> and currently use this approach</p>
  
  <pre><code>string country = requestedUri.Segments[3];
  </code></pre>
  
  <p>This method is fine for static URI's, but as soon as paths change it can be a lot of hassle to go back and make changes.</p>