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