I tried to think of situations where you really can use implicit conversion to an array. I began to wonder if many situations can be alleviated when you want to do this using the params keyword.
The main situation that I could think of was that you had one element of something and he wanted to pass it to a function that takes an array as a parameter:
static void Main(string[] args) { string x = "I'm just a poor variable. Nobody loves me."; Stickler.IOnlyTakeArrays_Rawr111(x);
I hope that in this situation, the author of the method you want to call selected params to use the keyword so that you can pass your variable without wrapping it into an array:
class DataConcierge { public static T Create<T>(int id) {
Of course, this will not help you in situations where you need to convert a variable into a single array of elements, but not as a parameter for a method or in situations where the author of the method did not use the params keyword.
But what would be the first situation? Array assignment for a property? Psh. How often does this happen?
And the last? If the author did not use the params keyword when they could do this, send them a letter complaining about it. If the author himself, feel free to be an additional warrior in the letter.
I hope you can say that I am doing well. Seriously, however, are there other common usage situations that you can think of where the params keyword will not apply?
** Disclaimer: I am not a supporter of the excessive use of the params keyword. Use it if you think you want, but do not accept my message so you always use the params keyword whenever you can.
source share