O'Reilly logo

Microsoft® Visual C#® 2008 Step by Step by John Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding static Methods and Data

In the preceding exercise, you used the Sqrt method of the Math class; similarly, when looking at the Circle class, you read the PI field of the Math class. If you think about it, the way in which you called the Sqrt method or read the PI field was slightly odd. You invoked the method on the class itself, not on an object of type Math. It is like trying to write Point. DistanceTo rather than origin.DistanceTo in the code you added in the preceding exercise. So what's happening, and how does this work?

You will often find that not all methods naturally belong to an instance of a class; they are utility methods inasmuch as they provide a useful function that is independent of any specific class instance. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required