Which is more efficient Cstr(value) or value.ToString()

前端 未结 9 1014
我在风中等你
我在风中等你 2021-01-11 14:56

I am wondering which is more efficient, using CStr() or object.toString(). The reason I ask this is because I though all that CStr() done was to invoke the .ToString() metho

9条回答
  •  爱一瞬间的悲伤
    2021-01-11 15:39

    CStr(object) is a cast (equivalent to (string)object in C#) and will throw esxception if given a null obejct or an object that cannot be casted to string. However .ToString() will work on any type of object (since it implemented in the Object class) and if not overridden by the current class will return the base ToString() method. In your case you must override ToString() method in your ID_TYPE class and return the string you need.

提交回复
热议问题