Skip to content

Commit 71abc70

Browse files
committed
Add EndsWith example; closes #18
1 parent 3213757 commit 71abc70

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

m/ends-with.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,33 @@
33
Determines whether the end of the first sequence is equivalent to the second
44
sequence.
55

6+
The following example checks whether the [segments] of a URL's path component
7+
end with a particular sequence or not:
8+
69
```c# --destination-file ../code/Program.cs --region statements --project ../code/TryMoreLinq.csproj
7-
// TODO add example
10+
var tail = new[] { "foo/", "bar/" };
11+
12+
var url1 = new Uri("http://example.com/foo/bar/");
13+
WriteLine(url1.Segments.EndsWith(tail)); // True
14+
15+
var url2 = new Uri("http://example.com/foo/bar/baz/");
16+
WriteLine(url2.Segments.EndsWith(tail)); // False
17+
```
18+
19+
The same example as above is expressed as a single query expression below:
20+
21+
```c# --destination-file ../code/Program.cs --region expression --project ../code/TryMoreLinq.csproj
22+
from url in new[]
23+
{
24+
"http://example.com/foo/bar/",
25+
"http://example.com/foo/bar/baz/",
26+
}
27+
select new Uri(url) into url
28+
select new
29+
{
30+
Url = url,
31+
EndsWithFooBar = url.Segments.EndsWith(new[] { "foo/", "bar/" }),
32+
}
833
```
934

1035
For more details, [see the documentation][doc].
@@ -18,3 +43,4 @@ improvement. Alternatively, you can also [report an issue you see][issue].
1843
[edit]: https://github.com/morelinq/try/edit/master/m/ends-with.md
1944
[issue]: https://github.com/morelinq/try/issues/new?title=EndsWith
2045
[doc]: https://morelinq.github.io/3.1/ref/api/html/Overload_MoreLinq_MoreEnumerable_EndsWith.htm
46+
[segments]: https://docs.microsoft.com/en-us/dotnet/api/system.uri.segments

0 commit comments

Comments
 (0)