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

前端 未结 9 953
我在风中等你
我在风中等你 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:54

    From here (couldn't say it any better):

    CStr is a keyword, whereas ToString is a function (method). CStr is compiled inline and it creates code depending on the type of the passed object. It's mainly there for people being used to it from previous VB versions. I haven't used CStr in .Net anymore (because it's not obvious what it does in which situations and it's also not very well documented).

    The difference depends on which ToString function you use. Every type can have it's own implementation.

提交回复
热议问题