The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Â
namespace ConsoleApplication2
{
  class Program
  {
  Â
      static void Main(string[] args)
      {
        Point origin = new Point();
        Point bottomRight = new Point(1366, 768);
        double distance = origin.DistanceTo(bottomRight);
        Console.WriteLine($"Distance is: {distance}");
        Console.WriteLine($"Number of Point objects: {Point.ObjectCount()}");
      }
    }
    class Point
    {
      private int x, y;
      private int objectCount = 0;
      public Point()
      {
        this.x = -1;
        this.y = -1;
        objectCount++;
      }
      public Point(int x, int y)
      {
        this.x = x;
        this.y = y;
        objectCount++;
      }
      public double DistanceTo(Point other)
      {
        int xDiff = this.x - other.x;
        int yDiff = this.y - other.y;
        double distance = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
        return distance;
      }
      public static int ObjectCount()
      {
        return objectCount;
      }
    }
  }
Â
I am getting this error
Â
Severity Code Description Project File Line Suppression State
Error CS0120 An object reference is required for the non-static field, method, or property 'Point.objectCount' ConsoleApplication2 C:UsersTrey PerrymanDocumentsConsoleApplication2ConsoleApplication2Program.cs 46 Active
Attachments: