Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')
问题 Why oh why is this not allowed: private static unsafe byte[] ConvertStruct<T>(T str) where T: struct { T* ptr = &str; int size = Marshal.SizeOf(str); var arr = new byte[size]; Marshal.Copy((IntPtr) ptr, arr, 0, size); return arr; } I get the compile error "Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')" Or is the "struct" constraint not enough? In the sense that it could still be an managed struct? Do I understand correctly that my struct might not