Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to overload the “as” or “is” operators

Is this allowed? If not, can this be accomplished inherently by overloading the implicit/explicit conversion operators?

like image 878
Joel B Avatar asked Dec 01 '22 09:12

Joel B


2 Answers

No. Check this: Overloadable Operators and this All C# operators

like image 37
petro.sidlovskyy Avatar answered Dec 05 '22 02:12

petro.sidlovskyy


Is overloading the "is" and "as" operators allowed?

No.

If not, can this be accomplished inherently by overloading the implicit/explicit conversion operators?

No. The "as" and "is" operators tell you what a thing really is. They pay no attention to user-defined conversions.

See

http://blogs.msdn.com/b/ericlippert/archive/2009/10/08/what-s-the-difference-between-as-and-cast-operators.aspx

http://blogs.msdn.com/b/ericlippert/archive/2010/09/16/is-is-as-or-is-as-is.aspx

for some more thoughts on the "as" and "is" operators.

like image 199
Eric Lippert Avatar answered Dec 05 '22 02:12

Eric Lippert