Question

I trip on C#'s String.Join and String.Split parameter types every time. The problem is that String.Split takes a params char[] array of characters and String.Join takes a string.

Does anyone have a good mnemonic that can help me remember which takes which so I do not have to fix this every single time I do a string manipulation?

[EDIT, since everyone seems to be confused why I don't have IDE support]

I'm using LinqPad, like this, when I use this most of the time:

String.Join("\n", @"LongRawString
WithPlentyOfLines
UsuallyGeneratedBySomeoneElse
OrProducedBySqlServerForExample".Split('\n').Select(x => 
    {
        x = x.Trim();

        //create line of code, like:
        return "int longRawStringIdx = reader.GetOrdinal(\"LongRawString\")";
    }))

I don't get IDE support in LinqPad, and would like to save the few seconds it takes me to go back and fix it every time. It's silly, but then so are half the scripts that we programmers write to automate the 12 second tasks we do every day.

The problem is that I screw up whether or not I'm supposed to be giving Split the string or Join the string as its first parameter (or only in the case of Split).

Was it helpful?

Solution

You could think of it this way: you're specifying one thing to join on, but several possible delimiters to split on. It makes sense that way round as the input string could already have many delimiters, but it doesn't make sense to join on multiple delimiters, as the Join method would have to work out which delimiter you meant each time.

I'd just use Intellisense though :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top