title: c# string constants vs static properies
body: <p>I have a class with predefined constant strings which are used as keys to retrieve the data from the external storage by provided key.</p>
  
  <pre><code>public class StorageKeys
  {
      public const string SomeKey = "Foo";
      public const string AnotherKey = "Foooo";        
  }
  
  public interface IStorage
  {
      string GetValue(string key);
  }
  </code></pre>
  
  <p>Which is used like this: </p>
  
  <pre><code>IStorage t = new Storage();
  string value = t.GetValue(StorageKeys.SomeKey);
  </code></pre>
  
  <p>It works but I'm concerned that potentiality it's possible to call <code>GetValue</code> method with just string argument which can cause an error: </p>
  
  <pre><code>string value = t.GetValue("Illegal key");
  </code></pre>
  
  <p>That's why I've come up with this idea:</p>
  
  <pre><code>public class StorageKeys
  {
      public static StorageKeys SomeKey = new StorageKeys("Foo");
      public static StorageKeys AnotherKey = new StorageKeys("Foooo");
  
      private StorageKeys(string key)
      {
          _key = key;
      }
  
      private readonly string _key;
  
      public static implicit operator string(StorageKeys key) =&gt; key._key;
  }
  
  public interface IStorage
  {
      string GetValue(StorageKeys key);
  }
  </code></pre>
  
  <p>After these changes my method can be used only with correct keys but I think it would decrease a performance because of static properties and implicit casting.</p>
  
  <p>So my question is it a good idea? </p>
  
  <p>Am I overconcerned? </p>
  
  <p>How much slower my second approach would be comparing to the first one?</p>
  
  <p>Is there another way to prevent passing wrong arguments?</p>