|
-
August 16th, 2012, 02:12 PM
#1
Error 1 An object reference is required for the non-static field, method, or property
Error 1 An object reference is required for the non-static field, method, or property 'ConsoleApplication_FileTest.Program.GetAverageSalary(string)' C:\Users\Dawn\documents\visual studio 11\Projects\ConsoleApplication_FileTest\ConsoleApplication_FileTest\Program.cs 98 24 ConsoleApplication_FileTest
static void Main(string[] args)
{
Dictionary<string, double> averages = new Dictionary<string, double>();
string filename = "c:\\test.txt";
averages = GetAverageSalary(filename)
}
=====================
Dictionary<string, double> GetAverageSalary(string filename)
{
...
-
August 16th, 2012, 06:52 PM
#2
Re: Error 1 An object reference is required for the non-static field, method, or prop
The Main() method is static, GetAverageSalary() is not, so it can't be called without an object.
Just add "static" in front of the declaration of GetAverageSalary() - just like the one Main() already present in front of Main().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|