1

I have an issue with an error I am getting in Vs2019, to do with non static fields using C# and would be grateful for some assistance

This is my method:

I have tried to debug code and made changes but cant find solution

     public void getrecs ()
      {
           
          SomeModel model = ServiceObj.ListServiceData(id, dStart, dEnd);
            
      }
      
      //Getting error on VS2019 - ServiceObj.ListServiceData
      //CS0120 An object reference is required for the nonstatic field, method, or property 'member'
      
      
      internal class ServiceObj : IServiceObj
      {
            //This is ListServiceData
      
            public IEnumerable<IEventDays> ListServiceData(Guid id, DateTime startDate, DateTime endDate)
            {
     
            }
            
      }
user1915984
  • 29
  • 1
  • 2
  • 4

1 Answers1

1

you need an instance of ServiceObj to call an instance method.

 public void getrecs ()
  {
       var so = new ServiceObj();
      SomeModel model = so.ListServiceData(id, dStart, dEnd);
        
  }
pm100
  • 48,078
  • 23
  • 82
  • 145