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

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...