(string)dr["FieldName"] vs dr["FieldName"].ToString();

  • Thread starter Thread starter ad
  • Start date Start date
ad said:
Hi,

What is the difference between
(string)dr["FieldName"]

casts dr["FieldName"] to a string.
dr["FieldName"].ToString();

Gives the string representation of dr["FieldName"]

If dr["FieldName"] is not an instance of string, that's definatly not
the same :)

Try to think of it as

class Bar: ToFoo {
Foo ToFoo() { return ...; }
}
Bar bar = new Bar();

now what is the diff between:

(Foo)bar;

and

bar.ToFoo();
 
Back
Top