c# - 在 c# 中使用静态类与编译器方式的过程编程相同吗?
问题描述
基本上我使用的是 Unity,它使用了 c#。我想按程序编程。我可以用静态命名空间和静态类来模仿它,这样我就可以将静态命名空间用作“头文件”,这样我就不必实例化一堆单例了。这种表现如何明智?
例如:
namespace Balls
{
public static Ball [] balls;
public static class Balls
{
public static void UpdateBalls (){}
}
}
另一个文件:
using static Balls;
namespace Player
{
public static class Player
{
public static bool PlayerAlive;
public static Vector3 position;
public static void UpdatePlayer ()
{
for (int i=0; i<balls.Length; i++)
{
if (position == balls[i].position)
{
PlayerAlive = false;
}
}
}
}
}
另一个文件:
using static Balls;
using static Player;
namespace Main
{
public static class Main
{
public static void MainUpdate ()
{
if (PlayerAlive)
{
UpdateBalls ();
UpdatePlayer ();
}
}
}
}
解决方案
推荐阅读
- c++ - Visual 2019 中的复制省略
- java - android中的AsyncTaskLoader函数错误
- java - 多次交互后 Android 活动滞后
- python - 在 CSV 文件上使用 for 循环附加空数据框
- javascript - 如何使用 Asp.Net Mvc 调用局部视图
- javascript - 使用 javascript/jquery,有没有办法阻止网页的其余部分加载,直到加载标题部分?
- google-data-studio - Google Data studio - 上个月数据为月份级别时的默认过滤器
- .net-core - 无法访问 .net Core 3 中的 resx 文件
- javascript - 是否可以使用 Ramda 从数组中获取中间元素?
- frontend - GoogleCreativeContainerClass 来自哪里?