问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/52485588/what-is-the-advantage-of-path-tryjoin-over-path-combine-in-net-core