Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Cannot take the address of, get the size of, or declare a pointer to a managed type ('type')
Even when used with the unsafe keyword, taking the address of a managed object, getting the size of a managed object, or declaring a pointer to a managed type is not allowed. A managed type is:
any reference type
any struct that contains a reference type as a field or property
For more information, see Unmanaged types.
The following sample generates CS0208:
// CS0208.cs
// compile with: /unsafe
class myClass
{
public int a = 98;
}
struct myProblemStruct
{
string s;
float f;
}
struct myGoodStruct
{
int i;
float f;
}
public class MyClass
{
unsafe public static void Main()
{
// myClass is a class, a managed type.
myClass s = new myClass();
myClass* s2 = &s; // CS0208
// The struct contains a string, a managed type.
int i = sizeof(myProblemStruct); //CS0208
// The struct contains only value types.
i = sizeof(myGoodStruct); //OK
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: