title: Find two sum function in c#
body: <p>I am trying to solve a problem in testdome online exam.</p>
  
  <p>the question is Write a function that, given a list and a target sum, returns zero-based indices of any two distinct elements whose sum is equal to the target sum. If there are no such elements, the function should return null.</p>
  
  <p>here is my code , it is just 75% true and the 25% to time is exceed </p>
  
  <pre><code>using System;
  using System.Linq;
  using System.Collections.Generic;
  
  class TwoSum
  {
      public static Tuple&lt;int, int&gt; FindTwoSum(IList&lt;int&gt; list, int sum)
      {
          var result = from n1 in list
                       from n2 in list
                       where n1 + n2 == sum
                       select new Tuple&lt;int, int&gt;(list.IndexOf(n1), list.IndexOf(n2));
          return result.FirstOrDefault();
      }
      public static void Main(string[] args)
      {
          Tuple&lt;int, int&gt; indices = FindTwoSum(new List&lt;int&gt;() { 1, 3, 5, 7, 9 }, 12);
          Console.WriteLine(indices.Item1 + " " + indices.Item2);
      }
  }
  </code></pre>
  
  <p>you can copy paste my code in the online website and see the result.
  can any one help me so we get 100% true. :D </p>
  
  <p><a href="https://www.testdome.com/Questions/Csharp/TwoSum/4318" rel="noreferrer">https://www.testdome.com/Questions/Csharp/TwoSum/4318</a></p>