C# Error CS8812 – Cannot convert &method group ‘{0}’ to non-function pointer type ‘{1}’.

C# Error

CS8812 – Cannot convert &method group ‘{0}’ to non-function pointer type ‘{1}’.

Reason for the Error & Solution

Cannot convert &method group to non-function pointer type.

Example

The following sample generates CS8812:

// CS8812.cs (6,22)

unsafe class C
{
    static void M()
    {
        void* ptr1 = &M;
    }
}

The address of an expression (e.g., &M) has no type and thus cannot be assigned to a non-function pointer variable.

To correct this error

Explicitly convert the expression to the required type (e.g., a void delegate):

unsafe class C
{
    static void M()
    {
        void* ptr1 = (delegate*<void>)&M;
    }
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...