Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS0077 

Error Message

The as operator must be used with a reference type ('type' is a value type)

The as operator was passed a value type. Because as can return null, it can only be passed reference types.

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;

Community Additions

© 2015 Microsoft