Generic pointers

suggest change

A 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
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents