CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    173

    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,074

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

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width