# Hi problem with exercises

Create a `KeepInBounds()` method. Without this method, hitting the boundaries will break the game!

Every time a key is pressed, it will be called twice: once for x and once for y. The method will constrain a coordinate between 0 and its maximum value to keep the character from going off-screen.

The method should:

• have the `public new static` modifiers
• return an `int`
• have two arguments: an `int` representing the coordinate, and an `int` representing the maximum value

Here’s how the method will be used. Imagine that the x-coordinate has a maximum of `10` (exclusive), so it should only take values from `0` through `9` :

// newX will be 1 newX = KeepInBounds(1, 10); // newX will be 0 newX = KeepInBounds(-1, 10); // newX will be 9 newX = KeepInBounds(10,10); // newX will be 9 newX = KeepInBounds(11,10);

public static new int KeepInBounds(int dimension, int max = 10)
{
int min = 0;
if (dimension <= min)
{
return dimension = 0;
} else if (dimension >= max)
{
return dimension = 9;
} else { return dimension;}

}
thanks.

what problem? I only see instructions

at the beginning there are the indications then there is the link … and then there is what I thought it was … at the end when I do “dotnet run” there are no limits on all sides … sorry my english — Google translator. Thank you

Your code isn’t valid C# so my guess is it didn’t compile and you are running a completely different program.