If someList
is empty, it will never enter the foreach
loop, and therefore z
will never be assigned. To resolve this, ensure that z
is given a value regardless of of the contents of someList
:
public int myMethod(int x, out int y, out int z)
{
z = 0; // or whatever default value you like
...
}
However, you should probably consider refactoring this code. It's likely there's a better way to accomplish this. If you'd really like to return 3 different int
values, you might consider using a Tuple<int, int, int>
or creating a custom data type to represent the value.