首页 > 解决方案 > 我应该在控制台应用程序中使用 System.Drawing 吗?

问题描述

我正在用 C# 制作控制台游戏,很多时候我必须管理对象的位置或大小。所以我想我PointSize使用System.Drawing. 但是,当我用谷歌搜索该命名空间时,有很多结果都在谈论 Windows 窗体,但是这些结构是否也用于控制台应用程序?还是人们只是为此制作自己的小结构?只是一个简单的问题,我想知道最佳实践是什么。

例子:

using System.Drawing;

class Entity
{
    public Point Position;
    public Size Size;

    // Other entity stuff
}

或者:

class Entity
{
    public int X, Y, Width, Height;

    // Other entity stuff
}

或者:

class Entity
{
    public Point Position;
    public Size Size;

    // Other entity stuff
}

struct Point
{
    public int X, Y;

    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }
}

struct Size
{
    public int Width, Height;

    public Point(int width, int height)
    {
        Width = width;
        Height = height;
    }
}

此外,该System.Drawing.Point结构附有很多东西,所以我不知道。

标签: c#.netconsole-applicationcoordinatessystem.drawing

解决方案


推荐阅读