C # 4.0 named parameters - should they always be used when calling non-Framework methods?
This is actually a very subjective topic, but here is my current trick:
When calling methods that are not part of the .NET BCL credentials, you should always use, as the method signatures can change a lot, especially during the development cycle of my own applications.
While they may seem more detailed, they are also much clearer.
Is the above a sane approach to calling methods, or am I missing something fundamental?
a source to share
I think it's from above, personally. (I also think it is more correct and understandable to call them named arguments - parameters are always named, as that part of the declaration.)
In many cases, the meaning is crystal clear in the name of the method - especially if there are only a couple of arguments. Why add a name? Why can this fact affect this fact?
I would suggest using named arguments:
- When using additional parameters
- When there are several parameters of the same type, they can be confused (for example, the title of the dialog box and the text of the text).
- When you use
null
for an argument and it's not clear what it does
In other words, how often the arguments were not named, are you confusing before C # 4? In my case, of course, this is a nonzero number of cases - the situations above, but this is not something that regularly bothers me. Optional parameters make it more reasonable for a method (or in particular a constructor) to have potentially many parameters, and this makes named arguments more useful (and really necessary if you want to specify "late" optional parameters. skipped earlier).
a source to share