title: How to make a combined method out of these two methods?
body: <p>I'm quite new to generics and I have a problem where two methods essentially do the same. The only difference is the parameter. </p>
  
  <p>I have a json list, with a lot of JSON objects, and I have two methods getting the different objects in two different ways. The object is a language object consisting of an ID and code. </p>
  
  <p>I have tried digging down in generics, since I think this is how I can solve this problem to make the code even nicer. However, I have a really hard time understanding it. </p>
  
  <p>The methods look like this.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public LanguageDto GetLanguageById(int id)
  {
      var o = JObject.Parse(json);
      var a = (JArray) o["list"];
      var _list = a.ToObject&lt;IList&lt;LanguageDto&gt;&gt;();
  
      return _list.FirstOrDefault(x =&gt; x.Id == id);
  }
  
  public LanguageDto GetLanguageByCode(string code)
  {
      var o = JObject.Parse(json);
      var a = (JArray) o["list"];
      var _list = a.ToObject&lt;IList&lt;LanguageDto&gt;&gt;();
  
      return _list.FirstOrDefault(x =&gt; x.LanguageCode == code);
  }
  </code></pre>
  
  <p>What I would like is a combined method that looks like this</p>
  
  <pre class="lang-cs prettyprint-override"><code>public LanguageDto GetLanguage(T)
  {
      var o = JObject.Parse(json);
      var a = (JArray) o["list"];
      var _list = a.ToObject&lt;IList&lt;LanguageDto&gt;&gt;();
  
      return _list.FirstOrDefault(x =&gt; x.T == T);
  }
  </code></pre>
  
  <p>I hope you get my pseudo code.</p>
  
  <p>If someone has some great learning resources on Generics or something that touches this problem, I would appreciate if you would share.</p>