C # static method with ref parameter - good idea?

I recently reorganized some code and now have a static utility class with this way:

const int x = 1;
public static string doWork(ref DataTable dt)
{
    decimal total = 0;
    foreach (DataRow row in dt.Select("COST_ID = " + x))
    {
        decimal annual = decimal.Parse(row["Cost"].ToString());
        total += decimal.Round(annual, 2);
    }
    return String.Format("{0:C}", total);
}

I simplified the example for clarity ...

Perhaps I experienced any negative consequences of this and placing the doWork method call in the code behind the ASP.NET application that affects many users? Does anyone know or have a link where I can read how, in terms of performance, the static method will work? Is it becoming a bottleneck of any kind?

EDIT:

Yes, I apologize, it was not a very good example, so let's say something else like this:

const int x = 1;
public static string doWork(ref DataTable dt)
{
    foreach (DataRow row in dt.Select("COST_ID = " + x))
    {
        row["Cost"] = 0.0;
    }
}

You say that A) I don’t even need a link here, since Datatable is already passed ref and B). Performance is not at all hit by β€œforwarding” all calls to one static method.

+3
7

ref . , , ( ). ref , , , .

ref : , , , .

, : ref .


, :

  • , ref , ( ).
  • , static const ID, .
+6

, (, Datatable) ref, - . Ref . .

+7

AFAIK , . , , this , , .

+2

"ref" .

+1

DataTable is already passed as a reference, so ref is not needed

+1
source

DataTable is an instance of a class that is passed by reference. Since you do not change the reference to the object, the keyword "ref" is not required.

+1
source

Not all methods staticwill increase performance when used ref. For more information, refsee This.

0
source

All Articles