Computers, Programming, Technology, Music, Literature

C# – if we didn’t have the is keyword

leave a comment »


I am so fixated with the as keyword these days, that I forgot how I’d do a type comparison if the as keyword never existed. We’d have to use a combination of myobj.GetType() and the typeof operator.

            catch (Exception eX)
                if (eX is SmtpFailedRecipientException)
                    Console.WriteLine("SmtpFailedRecipientException is thrown.");
                else if (eX.GetType() == typeof(SmtpException))
                    Console.WriteLine("SmtpException is thrown.");
                    Console.WriteLine("{0} is thrown.", eX.GetType().ToString());

Written by gmaran23

May 28, 2013 at 11:59 am

Posted in .Net, C#

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: