You can read all the C# performance tips from the following links,
C# has a total of 10 overload methods.
Most of the developers adopt the below approach.
- string str = "Akshay|Patel";
- Stopwatch s1 = new Stopwatch();
- s1.Start();
- string[] temp1 = str.Split('|');
- Console.WriteLine(s1.ElapsedTicks.ToString());
Let’s change the approach; i.e., rather than passing the character directly, let us create an array of characters and pass them as array elements.
- Stopwatch s2 = new Stopwatch();
- s2.Start();
- string[] temp = str.Split(new char[] {
- '|'
- });
- Console.WriteLine(s2.ElapsedTicks.ToString());
Run the application and compare the execution time.
The result suggests adopting the second approach to save the execution time.