2

Possible Duplicate:
Direct casting vs 'as' operator?

The as operator is similar to a cast. But i want to know the difference? And also i`ve doubt it is operator or keyword? :)

Community
  • 1
  • 1
Nagarajan S
  • 103
  • 1
  • 7
  • Duplicate of : http://stackoverflow.com/questions/132445/direct-casting-vs-as-operator – Tiax Jan 06 '11 at 06:35
  • Just to answer your second question: in C# `as` is a keyword *and* an operator: http://msdn.microsoft.com/en-us/library/bewds7kc.aspx – Michael Burr Jan 06 '11 at 06:45

2 Answers2

2

The as operator is the same as cast operator except that it yields null on conversion failure instead of throwing an exception

Luis
  • 5,979
  • 2
  • 31
  • 51
2

Both are used for casting, however AS will return a null if there is a cast mismatch where as the latter throws an exception. AS is an operator.

Chandu
  • 81,493
  • 19
  • 133
  • 134