[Solved] Which is more preferable? Performance or Memory while spliting a string in C#? [closed]


There’s no reason to do a computation that has the same result multiple times, especially if it involves memory allocations. You’re correct in that your first snippet has worse time and memory performance.

Every call to split will iterate over the string (probably the fastest part of all that), allocate two new arrays and copy a lot of substrings around. For operations such as this you should always store the result instead of making two calls.

Technically even property accesses can be stored with a very minor performance gain, but most of the time you shouldn’t bother unless in situations like above.

solved Which is more preferable? Performance or Memory while spliting a string in C#? [closed]