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

后端 未结 9 2100
终归单人心
终归单人心 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:39

    ToString() does not perform a cast by default. Its purpose is to return a string that represents the type (e.g. "System.Object").

    If you want to avoid casting you could try to think of an implementation that is strongly typed (using generics, for example) and avoids DataRowObject altogether.

提交回复
热议问题