public static int[] TwoSum(int[] nums, int target)
for (var i = 0; i < nums.Length; i++)
for (var j = 0; j < nums.Length; j++)
if (nums[i] + nums[j] == target)
public static int[] TwoSumWithLinq(int[] nums, int target)
(n,j) => new { n, m, i, j }
r.i != r.j && r.m + r.n == target
r => new int[] { r.i, r.j }
public static void Main()
new { nums = new int[] { 1,2,3,4,5 }, target = 3 },
new { nums = new int[] { 1,2,3,4,5 }, target = 6 },
new { nums = new int[] { 1,2,3,4,5 }, target = 7 },
new { nums = new int[] { 1,2,3,4,5 }, target = 9 }
var oldMatch = TwoSum( t.nums, t.target );
var newMatch = TwoSumWithLinq( t.nums, t.target );
"{0},{1} == {2},{3} (matching target {4} over array {{{5}}})",