c# - Calling ToString() gotchas -
I have read that ToString () uses reflection (although it should place quotation marks around the object, So it is called I where I do not know where / why can use this reflection) Is there any proof of this? And there is no performance penalty for calling. Toastring () (Maybe I should convert. Toastring (?)?
If you overwrite ()
do not override the method, you terminate the calling object.ostring () , whose implementation looks something like this:
public virtual string ToString () {return.GetType (). ToString (); } [MethodImpl (MethodImplOptions.InternalCall), Security Symptom] Public Extent Type Type (GETTYPE);
The method "Quotation marks around the object are not kept" To complete that result, it should get runtime type information and call it to ToString ()
, which in turn looks like this:
Public override string toasting () {return ("Type:" + this.Name); }
At any time you have a performance penalty for something through reflection, but in this case probably not really big to matter - unless you make it a lot Inside the inside are tight, very big loop.
Are you seeing a performance problem?
Comments
Post a Comment