I am trying to teach myself C#. I was working on an example when I came across something of interest (to me anyway), and none of my resource material explains why this happens. Can some one explain why this happens.
The code below works as it should
//calc test
//3/16/2010
public class calctest
{
static void Main()
{
double height = 5.5;
double width = 5.5;
double area;
area = height * width;
System.Console.WriteLine("area = {0}", area);
}
}
The code below however causes the following errors
Error 1 An object reference is required for the non-static field, method, or property 'calctest.area'
Error 2 An object reference is required for the non-static field, method, or property 'calctest.height'
Error 3 An object reference is required for the non-static field, method, or property 'calctest.width'
Can any one explain why?
//calc test
//3/16/2010
public class calctest
{
double height = 5.5;
double width = 5.5;
double area;
static void Main()
{
area = height * width;
System.Console.WriteLine("area = {0}", area);
}
}