c# - Are methods faster when parameters are referenced? -
this question has answer here:
- which faster? byval or byref? 7 answers
sometimes, got helper methods like:
private string generatereport(string doc, list<string> sheets, blah blahblah) { //dostuff() }
seeing lot of in code makes me wonder if i'm messing computer memory - throwing parameters , fro. on basic level, problem solved having class level variables in cases, may deriving class or using helper method class. question is:
is using references preferable option? i.e.
private string generatereport(ref string doc, ref list<string> sheets, ref blah blahblah) { //dostuff() }
and when should not use (if applicable)?
thanks.
the direct answer no. please see question , answer: which faster? byval or byref?
also remember passing reference should foremost design choice. passing reference states changes made parameters directly influence variables supplied. should used if want return more 1 parameter of if looking above behavior specifically.
and finally, if code not processing heavy should not focus on making small performance improvements rather focus on readability , stability.
Comments
Post a Comment