Everyone must have come across static keyword while doing development, specifically using C#. Static modifier is used to declare static member, which means it belongs to the type itself. Well, as part of this article, I’m not going to discuss more about static, but if you are interested in knowing more about it, here is a good reference.
- public class Logger
- {
- public static int GetLogLevel(string logType)
- {
- …
- }
- }
Above is a sample code snippet wherein, we have a class called Logger and it has a static method called GetLogLevel.
Now in order to call this GetLogLevel(…) method, first we have to add the required namespace, where this Logger class has been defined. Something like this,
- using Planner.Utilities;
Well, there's nothing new as of now. Next, let’s have a look at how to make a call to this static method.
- int logLevel = Logger.GetLogLevel(fileLog);
So far, it's nothing that bad, but we do have room to improve our code by making it more readable and cleaner. Let’s re-write our code in the below two steps,
Step 1 - Using static keyword along with namespace
- using static Planner.Utilities.Logger;
As we have already referred our class along with namespace, we need not to write that again. Hence, we can directly call our static method as shown below,
- int logLevel =GetLogLevel(fileLog);
What do you think about this approach? Isn’t it cool?

Graeme PariotPosted Mar 24, 2021, 1:54 AM
Simple but useful tip. Thanks for sharing.
Rajan MPosted Mar 3, 2021, 5:43 AM
For me, it is not worth using. If one use like this then they have to remember the method name of all static classes when using in the file. I think using class name with prefixed with static method is best approach in-terms of code readability and we don't have to remember the appropriate methods.
Shantoh SinghPosted Mar 2, 2021, 5:09 PM
Nice tip madam.