By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

What's best, return a large string or pass via "ref"?

P: n/a
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(ref strHTML)
{
}

Thanks in advance.
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Since the string type is a reference type, a reference to the string is
already returned from the GetReportHTML() method. Adding a parameter with
the ref keyword won't do anything for you. A ref param would only be used
if you wanted to change which object the parameter referred to, which is not
what you want to do in this case.

Joe
--
http://www.csharp-station.com

"Bob Maggio" <bc*****@yahoo.com> wrote in message
news:ef*************************@posting.google.co m...
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(ref strHTML)
{
}

Thanks in advance.

Nov 15 '05 #2

P: n/a
No. You are already passing back a reference to a string anyway.

-Rob Teixeira [MVP]

"Bob Maggio" <bc*****@yahoo.com> wrote in message
news:ef*************************@posting.google.co m...
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(ref strHTML)
{
}

Thanks in advance.

Nov 15 '05 #3

P: n/a
You probably should to do it a different way altogether. If the report is
large then the string will need to be created in memory. If you have a lot
of people hitting your site you will use much memory.

"Bob Maggio" <bc*****@yahoo.com> wrote in message
news:ef*************************@posting.google.co m...
I have created a function that returns a string containing raw HTML to
be used on a web form (see below):

private string GetReportHTML()
{
string strHTML = "";

// I have some code here that queries a database and
// formats the return DataSet as HTML and inserts
// this HTML into strHTML for return to the calling
// function

return strHTML;
}

This HTML content is a report. As such, there is potential for this
report, and thus the returned string size, to be very large.

My question is this, would there be any performance benefit by
changing this function from returning a string to accepting a "ref
string strHTML", considering this string could be very large? (see
below)

private void GetReportHTML(ref strHTML)
{
}

Thanks in advance.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.