C# array get last item from split in one line
You can use IEnumerable.Last() extension method from System.Linq.
string lastItemOfSplit = aString.Split(new char[] {@"\"[0], "/"[0]}).Last();
Like by using the IEnumerable.Last() extension method? Include System.Linq
and you'll have it.
You could always use LINQ:
string lastItem = aString.Split(...).Last();
Note that Enumerable.Last()
is optimized when working on an IList<T>
and you're not applying a predicate - so it's not even going to walk over the sequence to find the last one. (Not that it's likely to be an issue anyway.)