Casting vs Converting an object toString, when object really is a string

后端 未结 9 2098
终归单人心
终归单人心 2020-11-28 06:13

This isn\'t really an issue, however I am curious. When I save a string in lets say an DataRow, it is cast to Object. When I want to use it, I have to cast it ToString. As f

9条回答
  •  时光说笑
    2020-11-28 06:43

    In this case:

    string name = DataRowObject["name"].ToString();
    

    since it is a string, I think that the ToString() method of a string object is simple as:

    return this;
    

    so IMHO there is no performance penalty.

    PS I'm a Java programmer, so this anwser is only a guess.

提交回复
热议问题