简体   繁体   中英

C# declare class member variable type of itself pointer

I write linked list for study with C#

but, why this code occur error.

class testClass{
    testClass* pointerValue;
}

Error code:

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

i dont know why this error occur. help me

Since testClass has been declared as class (not as struct ) it's a reference type and you have no need in any explicit unsafe pointer :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM