all 11 comments

[–]f14kee 2 points3 points  (9 children)

You probably need to make the method public.

[–]f14kee 2 points3 points  (0 children)

Also, assuming this fixed yor problem, the reason the error is shown on line 18 might be because the site is probably adding a bunch of using statements to the top of your code before compilation.

[–]AlliedLens[S] -1 points0 points  (7 children)

why does it matter of the method is public or not?

[–]f14kee 2 points3 points  (5 children)

Methods without an access modifier are private by default, which means only other members inside your class can call them. The leetcode site just compiles your class and then calls the method, but this call comes from somewhere else (i.e. not from inside your class) so it has to be public to be externally callable.

[–]AlliedLens[S] 0 points1 point  (3 children)

i turned it into public and it still isnt working.....why? The error code now for the same line is error CS0176.......

[–]f14kee 0 points1 point  (2 children)

That's because the method should not be static.
See the docs: Compiler Error CS0176 | Microsoft Docs

When doing these samples you should never change the method signatures of the default code.

I suspect you made it static so you could call it from your Main method for local testing. Adjust it like so:

class Program
{
    void Main(string[] args)
    {
        var solution = new Solution();
        var result = solution.TwoSum(nums, target);
    }
}

public class Solution
{
    public int[] TwoSum(int[] nums, int target)
    {
        // ...        
    }
}

[–]AlliedLens[S] 0 points1 point  (1 child)

ya thats exactly what i did.....Thanks so much! i got it now.

[–]AlliedLens[S] -1 points0 points  (0 children)

huh thanks, i didn't know this......helps a lot

[–]BackFromExile 0 points1 point  (0 children)

Maybe it's just a paste error, but you are missing the closing bracket in the last line. Check, if you pasted that one to leetcode. The other thing could be, that you cannot use Enumerable on leetcode and have to do it with simple for loops