C# Language Pointers Generic pointers

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

The criteria that a type must satisfy in order to support pointers (see Remarks) cannot be expressed in terms of generic constraints. Therefore, any attempt to declare a pointer to a type provided through a generic type parameter will fail.

void P<T>(T obj) 
    where T : struct
{
    T* ptr = &obj; // compile-time error
}


Got any C# Language Question?