【问题标题】:How to define a class in C# [duplicate]如何在 C# 中定义一个类 [重复]
【发布时间】:2015-04-16 10:23:28
【问题描述】:

我是 C# 新手,我想要在 C++ 中像这样工作的东西

#define PointCloud List<PointData>

其中 PointData 是一个小类,其中包含有关点的一些数据,而 List 是通用 List。

问候

//编辑: PS:我要搜索的东西有名字吗?如果有,请告诉我。

【问题讨论】:

  • 最近的是:using PointCloud = List&lt;PointData&gt;;
  • 您可以使用using PointCloud = System.List&lt;PointData&gt; 在该源文件中创建一个可用的别名。但是 C# 不支持其他文件中可用的正确类型定义。根据上下文,从List&lt;PointData&gt; 派生PointCloud 可能是另一种选择。
  • 谢谢大家!这比我想象的要容易得多
  • 称为“使用别名指令”。

标签: c#


【解决方案1】:

我猜你的意思不是类,而是你可以使用“Using Alias Directive”。其语法如下:

using PointCloud = System.Collections.Generic.List<PointData>;

【讨论】:

    【解决方案2】:
    using PointCloud = System.Collections.Generic.List<PointData>;
    

    【讨论】:

      【解决方案3】:

      只需为 PointCloud 创建一个新定义

      class PointCloud : List<PointData>
      {
      }
      
      class PointData
      {}
      

      【讨论】:

      • 我认为 OP 正在寻找别名 List 而不是真正创建一个新类。
      • 这不是我要求的,但它甚至更适合我的情况,因为我可以在每个脚本中使用PointCloud。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多