Name difference between “is” and “as” operator in C#

Technology CommunityCategory: C#Name difference between “is” and “as” operator in C#
VietMX Staff asked 3 years ago
  • The is operator checks if an object can be cast to a specific type.
if (someObject is StringBuilder) ...
  • The as operator attempts to cast an object to a specific type, and returns null if it fails.
StringBuilder b = someObject as StringBuilder;
if (b != null) ...