Geeks With Blogs
Works on my machine December 2012 Entries
Overuse of “as” keyword
Recently I realized that I am overusing "as" keyword. It is probably because its syntax is more fluent for me than ordinary cast. I see this overuse even in Microsoft examples. Let the following code show you what I mean: object x = "1.0"; Version v = x as Version; Console.WriteLine(v.Major); and just for reference reasons ordinary cast: object x = "1.0"; Version v = (Version)x; Console.WriteLine(v.Major); When you run first snippet it will crash on third line throwing NullReferenceException. Second ......

Posted On Saturday, December 22, 2012 4:34 PM

Copyright © Jakub Niemyjski | Powered by: GeeksWithBlogs.net | Join free