I'm pretty new to C# and I'm trying to do something but without much success. I am trying to use the class Point
(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;
Console.WriteLine(p1.X);
Console.WriteLine(p1.Y);
Console.ReadLine();
}
}
}
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 Point
class/function which returns X and Y coordinates?
A class pointer is a pointer variable that stores address of an object of a class. As shown in the above diagram we have a class Rectangle with 2 data members and 1 member function. We have also created an object of that class named var1.
The Point and Line classes are a fundamental part of the C++ language. It is ubiquitous to use these classes when using the graphics library. They can be used to create graphs, animations, games, and more.
A pointer is a variable that stores the memory address of an object. The pointer then simply “points” to the object. The type of the object must correspond with the type of the pointer. Pointers are used extensively in both C and C++ for three main purposes: To allocate new objects on the heap.
1. C Classes. A class consists of an instance type and a class object: An instance type is a struct containing variable members called instance variables and function members called instance methods. A variable of the instance type is called an instance.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With