Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point class in C#

Tags:

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 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?

like image 614
ExtremeSwat Avatar asked May 14 '14 07:05

ExtremeSwat


People also ask

What is a class pointer?

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.

Does C++ have a Point class?

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.

What is type Point in C++?

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.

What is class in C with example?

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.


1 Answers

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:

SolutionExplorer

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.

like image 182
Alberto Solano Avatar answered Nov 10 '22 20:11

Alberto Solano