VS C# 2008 Object Reference Error

M

Mike

The snippet below is from a small console app I'm playin' around with in C#.
Upon building the app, I receive the error message "An object reference is
required for the non-static field, method, or property
bla.bla.ConvTempoToMilliseconds(int)".



int tempo = Convert.ToInt32(args[1]);

// ERROR on following line

display(ConvTempoToMilliseconds(tempo));


return;

}

public int ConvTempoToMilliseconds(int tempo)

{

// duration = 60000 / tempo

return 60000 / tempo;

}

Thanks for your thoughts,

Mike
 
L

Lee

The snippet below is from a small console app I'm playin' around with in C#.
Upon building the app, I receive the error message "An object reference is
required for the non-static field, method, or property
bla.bla.ConvTempoToMilliseconds(int)".

int tempo = Convert.ToInt32(args[1]);

// ERROR on following line

display(ConvTempoToMilliseconds(tempo));

return;

}

public int ConvTempoToMilliseconds(int tempo)

{

// duration = 60000 / tempo

return 60000 / tempo;

}

Thanks for your thoughts,

Mike

You've defined ConvTempoToMilliseconds as an instance method -- you
need an instance of the class containing it in order to reference it.
If you want to be able to reference the method then add 'static' to
its declaration -- public static int. Note that in you will then have
to reference it by its class-name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top