Reflection question

G

Guest

Hi,

is it faster to access the fields from an object directly by using
reflection than accessing them by their properties using reflection?

Thanks Christian
 
P

Patrick Steele

Hi,

is it faster to access the fields from an object directly by using
reflection than accessing them by their properties using reflection?

Direct access is always faster than reflection.
 
B

Bruce Wood

(e-mail address removed) says...

By the time you get through the machinery of Reflection, accessing a
property versus a field won't make much difference. You should
probably read and write the property, not the field, because that way
the object in question can make guarantees about its state. Messing
with an object's private fields is not good .NETiquette. :)
 
G

Guest

Hi Bruce,

thanks for your response. I know, that the field access should always be
realized by using a property. I had only a "developer discussion" if an
application will be faster if the access is faster by properties or directly
to the fields (both using reflection).

Bye
Christian
 
G

Guest

Hi Patrick,

thanks for your response.

My problem was not clearly described. The access to the fields is realized
with reflection, too.
 
B

Bruce Wood

Logically it should be a smidgen slower via the property, but
preferring to go after the field for that reason is like ordering Diet
Coke with your triple cheeseburger. After the triple cheeseburger, the
"Diet" part of "Diet Coke" doesn't really matter, and makes one look
silly, if you catch my drift.

Translated, if one does all of the work to ramp up the machinery of
Reflection, and then says, "Oh, I prefer to read the field rather than
the property, because it's faster," one sounds like a fool, IMHO.
 

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

Top