C # Method with maximum values? those. size (int x <40, int y <80)?

I wonder if there is a way to verify that the method input is correct? I understand that I can easily do this later and throw an error, but it would be nice if the compile time were caught.

Instead

CursorPosition(int x, int y)
{
 if (x >= 80) { Console.WriteLine("off screen"); }
 if (y >= 24) { Console.WriteLine("off screen"); }
}

Can't I just do it here, and compile the compiler and the error?

CursorPosition(int x < 80, y < 24)
{
 // do stuff
}

Many thanks!

+4
source share
1 answer

, , - , . , " 80" " , ", " , ", .

# . , , , , . , , , check-and-throw .

, , .

+5

Source: https://habr.com/ru/post/1684933/


All Articles