C# Error CS0244 – Neither ‘is’ nor ‘as’ is valid on pointer types

C# Compiler Error

CS0244 – Neither ‘is’ nor ‘as’ is valid on pointer types

Reason for the Error

You will receive this error in your C# code when you are using the “is” or “as” operators on pointer types with-in the unsafe block.

For example, try compiling the below code snippet.

namespace DeveloperPubNamespace
{
    public class BaseClass
    {
        unsafe static void PointerFunction(int* pointerInput)
        {
            var result = pointerInput is object;  
        }
    }

    class Program
    {
        public static void Main()
        {
        }
    }
}

This program will result with the C# error code CS0244 because the Function “PointerFunction” uses the “is” operator to check if the pointerInput is an object or not as this is not allowed in C#.

Error CS0244 Neither ‘is’ nor ‘as’ is valid on pointer types DeveloperPublish C:\Users\SenthilBalu\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 7 Active

C# Error CS0244 – Neither 'is' nor 'as' is valid on pointer types

Solution

The C# compiler does not allow the usage of the is and as operators on pointer types. Consider removing them when working with the pointer types.

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...