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 9230247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:46:39+00:00 2026-06-18T05:46:39+00:00

The following extract is from an FX Cop warning. Methods that do not access

  • 0

The following extract is from an FX Cop warning.

Methods that do not access instance data or call instance methods can
be marked as static (Shared in Visual Basic). After you mark the
methods as static, the compiler will emit non-virtual call sites to
these members. Emitting non-virtual call sites will prevent a check at
runtime for each call that ensures that the current object pointer is
non-null. This can result in a measurable performance gain for
performance-sensitive code. In some cases, the failure to access the
current object instance represents a correctness issue.

I understand the performance benefits of making private methods static if they don’t access instance data or methods but I’m not sure that in most cases the above advice is good. If you’re writing extremely performance critical code, and you’ve got no choice then to write it in c#, I can understand the sentiment but considering that generally, robust, easier to read, and easy to refactor code is preferred over performance should you actually follow this advice?

The problem I have with private static methods this that when you need to refactor a class I find that static methods make it more difficult to do so. If you have a large number of static methods, and you need to change one to use an instance variable, and that method is used by other private static methods, you end up having to make more changes in order to get this working. Below is an example (please bear in mind this is an minimal implementation just to demonstrate the point):

public class Test
    {
        private IService myService;

        private static void DoSomething()
        {
            DoSomethingElse();
        }

        private static void DoSomethingElse()
        {
            DoSomethingMore();
        }

        private static void DoSomethingMore()
        {
            Console.Write("DO SOMETHING");
        }
    }

If I want to use myService in the DoSomethingMore method, it means I have to make not only that method non-static, but the previous two methods as well. This seems burdensome.

What are other peoples thoughts on this?

  • 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-06-18T05:46:41+00:00Added an answer on June 18, 2026 at 5:46 am

    This seems burdensome.

    When you consider that the entire chain of function calls becomes dependent upon an instance when you modify your DoSomethingMore method, the feeling of the changes being “burdensome” should become “necessary” instead.

    What you should first consider are the semantics of the methods you’re writing. When you write a method, you need to ask yourself whether the code should be an instance method (because it should semantically be an action associated with a single instance) or a static method (for anything else) and that decision should drive how you write the method.

    Until you have measured performance shortcomings that are unacceptable in production code, you should make the method instance or static depending on what makes sense for your domain, not anything else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop an application that would extract the following things from an
I can't figure out how to get the following routes. Here's an extract from
I am using the following code to extract data from my database using entities.
I need to create a new table from data I extract from the following
I am writing a Perl script that needs to extract some data from an
I am trying to extract data from the following xml with no luck. <?xml
I am trying to run the following to extract the text from all the
How do I extract foo from the following URL and store it in a
Would it be possible to extract the following information from logs? Start up/Shut down
I'm trying to extract the following items from a C file: Comments (single and

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.