|
-
May 8th, 2004, 08:04 PM
#1
Thread Starter
Lively Member
Creating Classes (RESOLVED)
Why does VS.net let you use System.Math.Abs(double) without creating a new instance of it (System.Math math = new System.Math)? Ive been trying to make my own class that will find the area of circle, but it makes me create a new object first (ADGMathPro.Circle circle = new ADGMathPro.Circle();
What I was it to be able to do this....
ADGMathPro.Circle.Area(34);
instead of
circle.Area(34);
VB Code:
namespace ADGMathPro
{
/// <summary>
/// Summary description for Circle.
/// </summary>
public class Circle
{
const double pi = System.Math.PI;
public double Area(double radius)
{
double area;
area = pi * (radius * radius);
return area;
}
public double Circumference(double radius)
{
double circumference;
circumference = 2 * pi * radius;
return circumference;
}
}
}
What am I doing wrong??
Thanks
Last edited by JAtkinson; May 9th, 2004 at 01:26 AM.
Visual Studio .net 2003 EA
VB .net
C#
-
May 9th, 2004, 01:42 AM
#2
For those looking for an answer, it's a static method, which doesn't require an instance of the class to be created before it may be called; but it cannot access any non-static methods or properties of the containing class:
Code:
public MyClass
{
private string _myStringVariable = String.Empty; // This cannot be accessed by "MyMethod".
public static void MyMethod()
{
}
}
And to call the method:
Code:
MyClass.MyMethod();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|