C#中的点类 [英] Point class in C#

查看:66
本文介绍了C#中的点类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#还是很陌生,我正在尝试做一些事情,但没有取得太大的成功.我正在尝试使用 Point 类(带有坐标的类).

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).

这是代码:

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();
        }     
    }
}

错误是:

找不到类型或名称空间Point

The type or namespace Point could not be found

我在Java中使用此类的方式非常相似,是否应该声明自己的返回X和Y坐标的 Point 类/函数?

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?

推荐答案

您应该将对解决方案的引用添加到名称空间 System.Drawing .

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:

在新窗口中,输入搜索栏" System.Drawing ".双击找到的结果,然后单击确定"按钮.

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

现在,在您的代码中声明了其他 using 语句的位置,添加以下行:

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

using System.Drawing;

注意:我注意到您正在创建一个新的控制台应用程序.请注意,如果要创建基本的用户界面, System.Drawing.Point 结构将无济于事,因为在控制台应用程序中,您无法使用按钮,标签和坐标对放置UI项很有用.在控制台应用程序中,您只能使用纯文本进行交互.如果要创建具有基本用户界面的简单应用程序,请创建Windows Forms应用程序.

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.

这篇关于C#中的点类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆