ExtremeSwat ExtremeSwat - 8 months ago 57
C# Question

Point class in C#

I'm pretty new to C# and I'm trying to do something but without much success. I am trying to use the class

(the one with coordinates).

This is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace app2{
class Program{
static void Main(string[] args){

Point p1 = new Point();
p1.X = 7;
p1.Y = 6;



The error is :

The type or namespace Point could not be found

I've been using this class in Java in a very similar manner, am I supposed to declare my own
class/function which returns X and Y coordinates?


You should add a reference to your solution, to the namespace System.Drawing.

From the tab 'Solution Explorer', right click on 'References' and select 'Add Reference', as shown below:


In the new window, type in the search bar 'System.Drawing'. Double click in the results found and click the button 'OK'.

Now, in your code, where the other using statements are declared, add the following line:

using System.Drawing;

Note: I noticed you're creating a new Console application. Be aware that, if you want to create a basic user interface, the System.Drawing.Point structure won't help you, because in a Console application you cannot interact with the user using buttons, labels and coordinates useful to place your UI items. In a Console application, you can interact only using plain text. If you want to create a simple application with a basic user interface, create instead a Windows Forms application.