Cast versus parse

前端 未结 4 702
广开言路
广开言路 2021-02-14 14:19

I\'ve read a few related questions regarding this topic however none of them are making sense to me. As I understand it, in some cases you can use cast and parse interchangeably

4条回答
  •  广开言路
    2021-02-14 14:26

    Casting : is conversion of an object from a similar datatype; like from int to double or from decimal to int. Casting does not create a new object, It will only assign a reference of one datatype to reference of another datatype, only if its assignable.

    Parsing : Parsing, on the other side, is converting from one data type to another, like from string to int for example. This Creates a new Object, and returns reference to it.

    In a nutshell, Casting will not create a new object, but deal with the same object reference, whereas parsing create a new object, and doesn't touch the old object in any way.

提交回复
热议问题