I just started using .NET Core 2.1, and found the Path.TryJoin
and Path.Join
method. There is no documentation on the method.
I ran some unit tests calling the method, and it did nothing different than Path.Combine
.
Is there any advantage to this other than utilizing the new C# Span<T>
data type to minimize string manipulation execution?
Path. Combine uses the Path. PathSeparator and it checks whether the first path has already a separator at the end so it will not duplicate the separators. Additionally, it checks whether the path elements to combine have invalid chars.
A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path might map to a location in memory or on a device. The exact format of a path is determined by the current platform.
C# path class comes under System.IO namespace and System. Runtime. dll assembly. This class is used to perform operations on string instances that have file path or directory path information. A path is a string that holds the location of the file or directory and it can be an absolute or relative location.
You can find the rationale behind the Path.Join
being introduced here. IMHO it seems to be trading simplicity for performance and some minor fixes, also couldn't find any indication that Join creates cross-platform valid paths with the correct separators like Path.Combine
does but by all accounts is should.
To elaborate on the discussion, the main quirk that Path.Join
resolves is the last rooted argument which a lot of people don't expect to work the way it does (which seamed minor but clearly is not), as can be seen in the examples here on the the worst gotcha in C# or .NET page.
The general idea from the discussion is to slowly deprecate Combine
in favor of Join
.
Also note string overloads have been added for the Path.Join
with this PR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With