C# 声明类成员变量自身类型指针

标签 c#

我编写链接列表用于 C# 学习

但是,为什么这段代码会出现错误。

class testClass{
    testClass* pointerValue;
}

错误代码:

Cannot take the address of, get the size of, or declare a pointer to a managed type ('testClass')

我不知道为什么会出现这个错误。帮助我

最佳答案

由于testClass已被声明为class(而不是struct),它是一个引用类型,并且您有不需要任何显式的不安全指针:

class testClass { 
  // reference to testClass instance or null
  testClass pointerValue; 
}

关于C# 声明类成员变量自身类型指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421077/

相关文章:

c# - Console.WriteLine() 的高内存使用率

c# - 将自连接映射到代码优先 Entity Framework 4.3 中的集合

c# - 创建安装程序包 Visual Studio 2010

c# - 异步数据库操作

c# - IdentityServer4 unsupported_grant_type 错误

c# - 仅从 Excel (ACE OLEDB) 获取特定列

c# - 使用 BlockingCollection 作为消息队列的响应式(Reactive)框架

c# - 与委托(delegate)具有多个参数且没有 EventArgs 的事件集成

c# - 一个类应该包含它自己的集合吗?

c# - C# 中的计数排序实现