Method can be made static, but should it?

后端 未结 14 1106
说谎
说谎 2020-11-22 17:16

Resharper likes to point out multiple functions per asp.net page that could be made static. Does it help me if I do make them static? Should I make them static and move them

14条回答
  •  花落未央
    2020-11-22 17:51

    Just my tuppence: Adding all of the shared static methods to a utility class allows you to add

    using static className; 
    

    to your using statements, which makes the code faster to type and easier to read. For example, I have a large number of what would be called "global variables" in some code I inherited. Rather than make global variables in a class that was an instance class, I set them all as static properties of a global class. It does the job, if messily, and I can just reference the properties by name because I have the static namespace already referenced.

    I have no idea if this is good practice or not. I have so much to learn about C# 4/5 and so much legacy code to refactor that I am just trying to let the Roselyn tips guide me.

    Joey

提交回复
热议问题