There is a bug in the following piece of code. The bug could potentially break behaviours.
1 | private int ReturnDefaultYear(int? year) |
Found it yet? I’ll give you a hint. When passing parameters in .NET, value types are copied (int, double, float, etc.) but reference type (string, nullable, etc.) have their reference passed around. So when you change them, their value is not lost when leaving the method scope. They are persisted up to the highest level.
In this scenario, the parameter that was passed for “year” would become null.
Try running this simple code in a Console Application and you will understand the problem:
1 | class Program |