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

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

Hi,

What is the difference between
(string)dr["FieldName"]
and
dr["FieldName"].ToString();
 
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();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top