I'm facing the following error in C# Visual Studio that I just can't resolve:
"An object reference is required for the non-static field"
I don't know what it means nor how to fix it. Sure, I checked online but didn't find anything that spoke to my simple code below. All I want to do is call the following from Main() successfully:
int result = MaxPair(nums);
Many thanks in advance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MaxPairSpace
{
class Program
{
static int Main(string[] args)
{
int n = Int32.Parse( Console.ReadLine() );
string input = Console.ReadLine();
string[] split = input.Split(' ');
int length = split.Length;
int[] nums = new int[length];
for (int x = 0; x < length; x++)
{
nums[x] = Int32.Parse(split[x]);
}
int result = MaxPair(nums);
Console.WriteLine("{0}\n", result);
return 0;
}
public int MaxPair(int[] numbers)
{
int result = 0;
int n = numbers.Length;
for (int i = 0; i < n; ++i)
{
for (int j = i; j < n; ++j)
{
if (numbers[i] * numbers[j] > result)
{
result = numbers[i] * numbers[j];
}
}
}
return result;
}
}
}