Error 1 An object reference is required for the non-static field, method, or property
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Error 1 An object reference is required for the non-static field, method, or property

  1. #1
    Join Date
    Dec 2005
    Posts
    180

    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)
    {
    ...

  2. #2
    Join Date
    Jan 2010
    Posts
    1,102

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center