Timeline for Exercise: Design a Stack
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 8, 2020 at 14:46 | comment | added | Aron |
Also for the record, to get the last item in a list you could use list.Last() (or list.LastOrDefault().
|
|
| Apr 7, 2020 at 23:46 | comment | added | Aron |
Yes, FirstOrDefault() will return list[0] or null.
|
|
| Apr 7, 2020 at 21:55 | comment | added | Milliorn | So either I use that and handle an exception, or pass a null? Trying to make sure I am reading this right? (docs.microsoft.com/en-us/dotnet/api/…) | |
| Apr 7, 2020 at 21:26 | comment | added | Aron |
Hi, you're welcome. The risk with Top => list[0] is that when the list is empty it will throw an exception.
|
|
| Apr 7, 2020 at 18:05 | comment | added | Milliorn |
Thanks for your suggestions. I added your suggestion HasItems. Also added the Top property but why not public object Top => list[0];? link to latest code
|
|
| Apr 7, 2020 at 11:55 | history | edited | Aron | CC BY-SA 4.0 |
deleted 28 characters in body
|
| Apr 7, 2020 at 11:50 | history | edited | Aron | CC BY-SA 4.0 |
Removed IEnumerable. Added ToList(), with additional commentary on why.
|
| Apr 7, 2020 at 11:35 | history | answered | Aron | CC BY-SA 4.0 |