Use the as operator whenever you can because it is safer than casting and more efficient at runtime. The as and is operators do not perform any user-defined conversions. They only succeed if the runtime type matches the sought type and rarely construct a new object. The exception is the as operator will create a new type when converting a boxed value type to an unboxed nullable value type.
Related: https://github.com/BillWagner/EffectiveCSharpAnalyzers/issues/3
Use the
as
operator whenever you can because it is safer than casting and more efficient at runtime. Theas
andis
operators do not perform any user-defined conversions. They only succeed if the runtime type matches the sought type and rarely construct a new object. The exception is theas
operator will create a new type when converting a boxed value type to an unboxed nullable value type.