2

Those of you working with .NET, do you prefer C# casting syntax:
(Type)variable;

Or VB casting syntax:
variable as Type;

Comments
  • 7
    Depends on the situation since they work in different ways. "as" will give null if cast fails. "(type)" will cast exception if it fails. "as" can only be used on nullable types. "as" is nicer when youre unsure if the cast will succeed(just check if result != null)
  • 1
    @machinist oh man I never knew this. This changes everything!
  • 0
    I'm converting my skill set from vb to c#
Add Comment