Skip to main content

What is the difference between is and as operators?

Junior C#
Quick Answer is checks if an object is compatible with a type รขโ‚ฌโ€ returns true or false, never throws. as attempts a cast and returns null on failure instead of throwing InvalidCastException. Modern C# combines both: if (obj is MyType x) checks the type and assigns in one clean step.

Answer

is: Checks whether an object is of a specific type.

as: Attempts conversion and returns null if conversion fails.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice