Re: my first class - getting an error
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 10 Sep 2007 17:14:59 -0700
vinnie wrote:
I did my first project with the classes, but i get an error that i
don't understand, and so don't know how to correct it.
I'm not sure what the problem you're having interpreting the error is, but I _suspect_ you are being led astray by the "...and no extension method blah blah blah" part. A similar example is the error in .NET 2.0 that says the "best overload" doesn't take certain parameters.
This is a pet peeve of mine, with respect to the compiler errors. In some cases, in a well-intentioned effort to provide you with additional guidance, the compiler introduces some concept that you may not even be aware of, completely confusing the issue.
My guess is that if you just look at the very first clause in the error -- "'mixed_class.Program' does not contain a definition for
> 'Calculus'" -- you'd figure it out on your own. But with all that other stuff, a "newbie" is left scratching their head trying to figure out what it _all_ means.
In your specific situation, the issue here is that you are using an instance of a "Program" class, "So", to try to call the "Calculus" method. But the "Calculus" method exists in the "summing" class, not the "Program" class. So what you actually need is an instance of the "summing" class.
In fact, since at least right now your "Program" class only contains a single static method, I don't see any reason to ever instantiate it.
Change these two lines:
Program So = new Program();
so that it instead reads:
summing So = new summing();
and the error should go away.
As a more general rule, you should really try hard to break compiler messages (errors or otherwise) into small enough pieces so that you can really understand what they are saying. The error you got is pretty clear about what the problem is, as long as you can avoid getting overwhelmed by the stuff you don't understand.
In this case, the compiler clearly explained that the "Program" class you're trying to use doesn't contain the "Calculus" method that you're trying to call. That should have been able to lead you directly to realizing that you had the wrong class when you were trying to call "Calculus". Since you should have expected the compiler to be looking for "Calculus" in the "summing" class, from that error it should have been simple to just figure out why the compiler is looking at the wrong class. And of course, that turns out to be because the variable is the wrong type. :)
Pete
.
- Follow-Ups:
- Re: my first class - getting an error
- From: Paul
- Re: my first class - getting an error
- References:
- my first class - getting an error
- From: vinnie
- my first class - getting an error
- Prev by Date: need help with string format
- Next by Date: Re: need help with string format
- Previous by thread: my first class - getting an error
- Next by thread: Re: my first class - getting an error
- Index(es):
Relevant Pages
|