-2

Picture of code: http://prntscr.com/gm7cqv

I'm making a program that calculates the maximum and average speed of a car from array of objects, and I'm getting this problem and am not sure how to fix it:

An object reference is required for the non-static field, method, or property 'Program.niz' G6

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • https://stackoverflow.com/questions/4124102/whats-a-static-method-in-c – Slai Sep 17 '17 at 13:31
  • 1
    Have you even *tried* to search for this error? There are thousands of questions like this, e.g. https://stackoverflow.com/questions/10264308/c-sharp-error-an-object-reference-is-required-for-the-non-static-field-method Apart from this don´t paste images of your code, because it´s impossible to search for keywords in your code within a search-engine. Intead post your actual code diretly to the question, but just the *relevant* code, not your entire code-base. – MakePeaceGreatAgain Sep 17 '17 at 13:37
  • You should include the code in the question, not make a picture if it. – Peter Mortensen Oct 15 '17 at 22:34

1 Answers1

2

You have to make your array static

static Auto[] niz = new Auto[3];

Or you have to create an instance of the class that contains the array (notice method metoda is not static then)

rezultat = new Program().metoda();

public string metoda() {...
ironstone13
  • 3,325
  • 18
  • 24