That is if we were to see how Microsoft wrote this method what would it look like?
I’m mainly interested in the use of the StringSplitOptions enumeration with the other parameter and how they probably structured their code to account for each option.
To find out what the implementation looks like for any part of the Framework, you can do one of two things:
- You can download the .NET Framework Source Code from here, or
- You can use a decompiler, like Telerik JustDecompile.
The latter choice is by far the easiest.
I downloaded and installed JustDecompile, and loaded up .NET Framework 3.5. Then I opened up mscorlib.dll (where the String class is located) and looked at the Split methods.
Without getting into too much detail, there’s an if
statement that checks the StringSplitOptions
enumeration, and runs one of two different methods depending on which StringSplitOptions
setting is specified. The two methods are called InternalSplitKeepEmptyEntries
and InternalSplitOmitEmptyEntries
. They are pretty much two completely different implementations.
4