3 ms·
> graphics.DrawRectangle(RedBrush, new(3, 5, 2, 2)) > graphics.DrawRectangle(RedBrush, new Point(3, 5, 2, 2)) what's the advantage of the first example? i pre
by woodrowbarlow 6y ago
> graphics.DrawRectangle(RedBrush, new(3, 5, 2, 2))
> graphics.DrawRectangle(RedBrush, new Point(3, 5, 2, 2))
what's the advantage of the first example? i prefer the second, because i don't have to look at the definition of DrawRectangle in order to know that the second argument is a 'Point' object.
- maxton 6y agoThe second argument is a Rectangle, which means you'd be repeating 'Rectangle' twice in one line with the second style.
- surye 6y agoI think this clarification proves his point, and I tend to agree that I prefer the more explicit, verbose style.
- Infinitesimus 6y agoThat's not obvious from the function name though. The function definition could easily be `DrawRectangle(SolidColor, CornerRadii, Point)` and you wouldn't know by seeing a bunch of `DrawRectangle(RedBrush, new(1,2,4,5), Point(4,5,2,2))` would you? It's still nice to have the option in cases where it improves readability (maybe with named args or sth)
- deleted 6y ago[deleted]
- yread 6y agoSomeone in the comments also mentioned array initializers, arguably a better use of the feature.
- nycdotnet 6y agothis specifically. new List<KeyValuePair<string,int>> { new (“a”, 1), new (“b”, 2) } versus having to barf out the type name for every element will be REALLY nice.
- jayd16 6y agoTooling can show it. Rider will show it for you, I'm sure. Saves some typing but it also has refactor implications too. If you change the parameter type, it would change the object being constructed.