using System.Collections.Generic;
public static void Main()
int[] result = TwoSum(new int[] {3,2,4}, 6);
Console.WriteLine(result[0].ToString() + " + " + result[1].ToString());
public static int[] TwoSum(int[] nums, int target) {
for(a = 0; a < nums.Length; a++)
for(b = (a + 1); b < nums.Length; b++)
if((nums[a] + nums[b]) == target)
return new int[] { a, b };
return new int[] { a, b };
public static int[] TwoSum_NotWorking(int[] nums, int target) {
int[] temp = nums.Where(s => (Array.IndexOf(nums, s) != Array.IndexOf(nums, num))).ToArray();
if((target - num) == target) temp = nums.Where(s => (Array.IndexOf(nums, s) != Array.IndexOf(nums, num))).ToArray();
if(temp.Contains(target - num))
a = Array.IndexOf(nums, a);
b = Array.IndexOf(nums, b);
return new int[] { a, b };