Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:46:59+00:00 2026-05-23T02:46:59+00:00

I recently refactored some code and now have a static utility class with a

  • 0

I recently refactored some code and now have a static utility class with a method like so:

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’ve simplified the example for clarity…

Am I likely to experience any ill effects of doing this and putting a call to the doWork method in the code behind of an ASP.NET application being hit by many users? Anyone know or have a reference where I can read up on how, performance-wise, the static method will work? Does this become a bottleneck of any kind?

EDIT:

Yes I apologize this was not a very good example, so lets say something more 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’re saying that A) I don’t actually even need the ref here, since Datatable is already passed by ref and B) The performance is not hit at all by “funneling” all calls to the single static method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:47:00+00:00Added an answer on May 23, 2026 at 2:47 am

    The ref keyword is not used for performance purposes. It is used when you would like to alter what a variable in another scope points-to (in simple terms). Your use of ref in this instance is extraneous, and likely to lead to problems in the future.

    My rule of thumb for ref is: if you are using it, you probably shouldn’t be.

    Finally, to answer your question about performance: using ref will not change the performance envelope of the method on hand.


    After reading your edit, here are direct answers to your two questions:

    1. Correct, using ref is only going to cause confusion as this is not its intended usage (and it isn’t used for performance).
    2. Correct, using a static method with a const ID variable is not likely to improve performance in any measurable fashion for your scenario.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently refactored some code, and a method the original Global.asax.cs file was depending
I recently refactored some of my code to stuff rows into a db using
I recently refactored some code in an Active Directory role provider to remove support
I have twice recently refactored code in order to change the order of parameters
Recently, i took ownership of some c++ code. I am going to maintain this
Recently I refactored the code of a 3rd party hash function from C++ to
Recently I found some simple source code of a bootloader.The following is the simple
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I started changing some of our applications to support MS SQL Server as
Recently a friend and I were talking about securing stored procedure code in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.