Ok, this is probably highly subjective but here it comes:
Let’s assume I’m writing a method that will take a printscreen of some region of the screen. Which method signature would you prefer and why?
- Bitmap DoPrintScreen(int x, int y, int width, int height);
- Bitmap DoPrintScreen(Rectangle rect);
- Bitmap DoPrintScreen(Point point, Size size);
- Other
Why?
I keep seeing myself repeatedly implementing both 1) and 2) (redirecting one of them to the other) but I end up usually just using one of them, so there really is no point in having both. I can’t decide which would be better. Maybe I should use the signature that looks the most with the method I’ll be calling to make the printscreen?
The best one is
If you think about the method parameters as being part of a “concept”, in this case the concept of a screen area, then the other options don’t abstract that concept nicely enough.
Also, use a good name for the parameter, because it might make calling code even more clear by the use of named parameters in C# 4.0.