c# - 使用静态构造函数时 Visual Studio 的智能感知中断

标签 c# .net visual-studio-2013 struct static-constructor

我对 visual studio 的智能感知有疑问。 每次我在结构中创建 C# 静态构造函数时,visual studio 的智能感知都会在尝试调用构造函数时中断。 它似乎找不到构造函数,甚至连默认构造函数都找不到。 有谁知道我为什么会遇到这个问题?

    public Triangle(int aX, int aY, int bX, int bY, int cX, int cY)
    {
        A = new Point(aX, bY);
        B = new Point(bX, bY);
        C = new Point(cX, cY);
    }

    public Triangle(Point a, Point b, Point c)
    {
        A = a;
        B = b;
        C = c;
    }

    public Triangle(Triangle value)
    {
        A = value.A;
        B = value.B;
        C = value.C;
    }

    static Triangle()
    {
        Empty = new Triangle(0, 0, 0, 0, 0, 0);
    }

No intellisense

最佳答案

你不能直接调用static constructor ,并在创建第一个实例或引用任何静态成员之前自动调用它来初始化类型。

这里是静态构造函数规范的总结

  • A static constructor does not take access modifiers or have parameters.
  • A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
  • A static constructor cannot be called directly.
  • The user has no control on when the static constructor is executed in the program.
  • A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.
  • Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.
  • If a static constructor throws an exception, the runtime will not invoke it a second time, and the type will remain uninitialized for the lifetime of the application domain in which your program is running.

关于 Visual Studio 中的问题:

我对其进行了测试,一切正常。 enter image description here

关于c# - 使用静态构造函数时 Visual Studio 的智能感知中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31104479/

相关文章:

c# - 在 MouseEvent 中获取成员的父类

c# - 使用 iTextSharp 锁定 PDF 以防止编辑

.net - 关于 TypeLoadException 的帮助

c# - 如何在 C# 代码中创建 ImageBrush

c# - 如何制作自己的事件处理程序?

.net - Web部署 API (IIS 7) - "public API": resources?

c# - 在构建期间将许可证文件复制到 bin 文件夹

javascript - onDeviceReady() {...} 没有方法 'bind'

visual-studio-2013 - 通过命令行发布 lightswitch 应用程序不起作用

c# - 如何使用 SpreadsheetGear 以编程方式设置已定义名称的范围?