title: How to convert a List<string>() to Dictionary<string,string>() using LINQ in C#
body: <p>I have a <code>List</code> and I want to convert it to a <code>Dictionary</code>.  I don't have any problem in converting a <code>List</code> to <code>Dictionary</code> but I want to check if the key in the <code>Dictionary</code> is present or not, if present I should neglect the <code>KeyValuePair</code> and proceed with the next string.</p>
  
  <p>Here is the example.</p>
  
  <pre><code>IEnumerable&lt;String&gt; readlines = File.ReadAllLines("C:\Text.txt");
  List&lt;string&gt; lines = new List&lt;string&gt;();
  lines = readlines.ToList();
  Dictionary&lt;string, string&gt; keyPair= new Dictionary&lt;string, string&gt;();         
  keyPair= test.ToDictionary(s=&gt;s.Split('=')[1], s=&gt;s.Split('=')[0]);  
  keyPair.Keys.ToList().Sort();
  </code></pre>
  
  <p>If the same key repeats , the lambda expression throws and exception and I want to check whether the key exists or not and proceed with converting next string to dictionary.
  I want to convert the dictionary back to List once the key sorting is done.
  Is there any way to do it with LINQ? </p>