Compiler Error CS0077
The as operator must be used with a reference type or nullable type ('int' is a non-nullable value type).
The as operator was passed a value type. Because as
can return null, it can only be passed a reference type or a nullable value type.
The following sample generates CS0077:
// CS0077.cs
using System;
class C
{
}
struct S
{
}
class M
{
public static void Main()
{
object o1, o2;
C c;
S s;
o1 = new C();
o2 = new S();
s = o2 as S;
// CS0077, S is not a reference type.
// Try the following line instead.
// c = o1 as C;
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for