Generic pointers
suggest changeA pointer type has to be unmanaged: no references to managed objects. A struct constraint does not express that, so the method below does not compile. It is also outside an unsafe context. Since C# 7.3, where T : unmanaged does allow T* inside unsafe code.
void P<T>(T obj)
where T : struct
{
T* ptr = &obj; // compile-time error
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents