Casting DataTypes with DirectCast, CType, TryCast

后端 未结 4 1960
半阙折子戏
半阙折子戏 2020-12-01 05:22

Ever since I moved from VB6 to VB.NET somewhere in 2005, I\'ve been using CType to do casting from one data type to another. I do this because it is simply faster to type, u

4条回答
  •  醉梦人生
    2020-12-01 05:43

    This page explains it well.

    Reading it, I think that when you use DirectCast, you are sure that conversion will work without narrowing or expansion (in this case, numeric data). Whereas, CType will try to convert to it,with developer being aware of narrowing/expansion.

提交回复
热议问题