Question
So I'm wokring in C# programming and I am very close to getting this code to run but I can't figure out what I'm missing.
So I'm wokring in C# programming and I am very close to getting this code to run but I can't figure out what I'm missing.
Here's what I have:
#region Using directives using System; using System.Collections.Generic; using System.Text; #endregion namespace Classes { class Program { static void DoWork() { 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 static 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++; } private 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; } } }
The error that pops up is this: Error CS1061: 'Point' does not contain a definition for 'distanceTo' and no extension method 'distanceTo' accepting a first argument of type 'Point' could be found (are you missing a using directive or an assembly reference?) (line 14 origin.distanceTo) What am I missing?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started