How to Write a static Method in C#
Some methods belong to a class but need no object of it: checking whether a quantity is allowed, building a value from what you pass in. In C#, mark such a method static and call it on the class name. Methods without static belong to one object and work with its data.
Syntax
class <ClassName>
{
public static <ReturnType> <MethodName>(<parameters>) => <expression>;
}
<ClassName>.<MethodName>(<arguments>);
| Part | What it does |
|---|---|
static | Makes the method belong to the class itself, not to an object |
<ClassName>.<MethodName>(...) | Calls it through the class's name, without creating an object |
| What it can use | Its parameters and other static members, but not the fields and properties of an object |
Microsoft's static modifier reference: "Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object." Its static members guide adds: "The static member is always accessed by the class name, not the instance name."
The Example
An Order has an item and a quantity. Its static method IsValidQuantity checks whether a quantity is allowed, which needs no order at all, while its ordinary method Describe describes one order.
Prerequisites
- The .NET 10 SDK or newer, which runs a single
.csfile withdotnet run. This guide uses .NET SDK 10.0.404.
Step 1: Write the Code
Create a file named main.cs in an empty folder:

Console.WriteLine(Order.IsValidQuantity(3));
Console.WriteLine(Order.IsValidQuantity(0));
Order order = new() { Item = "Tea", Quantity = 3 };
Console.WriteLine(order.Describe());
class Order
{
public string Item { get; set; } = "";
public int Quantity { get; set; }
public static bool IsValidQuantity(int quantity) => quantity >= 1 && quantity <= 10;
public string Describe() => $"{Quantity} x {Item}";
}
Step 2: Run It
dotnet run main.cs
True
False
3 x Tea

Order.IsValidQuantity(3)and(0)ran before any order existed: a static method needs none.order.Describe()was called on one order, and read that order'sQuantityandItem.
The command is the same in zsh, bash and PowerShell.
A static Method Can't See an Object's Data
A static method has no order to read from, so it can't use Quantity:
Console.WriteLine(Order.IsValid());
class Order
{
public int Quantity { get; set; }
public static bool IsValid() => Quantity >= 1;
}
/Users/you/demo/main.cs(7,37): error CS0120: An object reference is required for the non-static field, method, or property 'Order.Quantity'
The build failed. Fix the build errors and run again.
The guide: "Static methods and properties can't access non-static fields and events in their containing type, and they can't access an instance variable of any object unless it's explicitly passed in a method parameter." Pass the value in as a parameter, as IsValidQuantity(int quantity) does.
Call It on the Class, Not on an Object
Calling a static method through an object doesn't compile either:
Order order = new();
Console.WriteLine(order.IsValidQuantity(3));
class Order
{
public static bool IsValidQuantity(int quantity) => quantity >= 1 && quantity <= 10;
}
/Users/you/demo/main.cs(2,19): error CS0176: Member 'Order.IsValidQuantity(int)' cannot be accessed with an instance reference; qualify it with a type name instead
The build failed. Fix the build errors and run again.
Write Order.IsValidQuantity(3).
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Reading a property of the object inside a static method | error CS0120: An object reference is required for the non-static field, method, or property | Pass the value as a parameter, or drop static |
| Calling a static method through an object | error CS0176: ... cannot be accessed with an instance reference; qualify it with a type name instead | Call it on the class name |
| Making a method static that needs an object's data | It can't reach the data | Keep it an instance method |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
CS0120 inside a method | The method is static but uses instance data | Pass the data in, or remove static |
CS0176 on a call | object.Method() for a static method | ClassName.Method() |
FAQ
When should a method be static?
When it works only with what you pass in, like IsValidQuantity, and doesn't need an object's fields or properties. If it needs them, like Describe, it's an instance method.
Can a normal class have static methods?
Yes, as Order does: a class can mix static and instance members. A class marked static can hold only static ones.
Conclusion
A static method belongs to the class: call it as ClassName.Method(), with no object, and give it what it needs as parameters. It can't read an object's data, CS0120, and it can't be called through an object, CS0176.
Additional Resources
- The static modifier, on Microsoft Learn.
- Static classes and static class members, on Microsoft Learn.
