Any difference between these two lines of code?
1) someString.Split(new[] { ';' });
2) someString.Split(';');
I see the first one in the code I’m working on and was wondering if I could safely change it to number two or why they chose to do it the first way.
Thanks.
The method argument is
params char[]. Theparamskeyword means you can provide an array explicitly, or let the compiler create one for you. In your first form, you are providing the array explicitly. You will need to use this form, of course, if you want to use other overloads of the method to specify additional behaviors. Otherwise, you can simply use your second form and list the separators in line and comma-delimited for ease of use.Why the previous coder(s) chose the first form over the second, I cannot say. I am not aware of a method form in a previous framework version that required the explicit array. However, you should be safe to change forms if you so choose, and you will assuredly test to verify the expected behavior.