Tag Archives: parameter

How to use default parameter in C# 2.0 & 3.5

For example, I need a method like this:

public void InitData(int index, object value, bool required = false) {}

I can write it as:

The attribute Optional tells compiler that the parameter required has default value. And the attribute DefaultParameterValue(false) tells compiler what is the default value.

Very simple. Isn’t it?