List.Count does not work
See original GitHub issueThis issue has been moved from a ticket on Developer Community.
Create a standard Blazor WASM project. Change the code of the counter Page to the below code Run it, watch it just completely crash when trying to load the page. See attachments
@page "/counter"
@try
{
@for (int i = 0; i < NumberBiggerThanListSize; i++)
{
@if (Strings.Count < i)
{
<div>@Strings[i]</div>
}
else
{
<div>@i is outside the bounds </div>
}
}
}
catch (Exception ex)
{
<div>@ex. ToString()</div>
}
@code {
private List<string> Strings = new List<string> { "String one", "String 2" };
private int NumberBiggerThanListSize = 5;
}
Original Comments
Feedback Bot on 7/30/2020, 07:28 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
why is the below list count method for Python3 not working.?
I am trying to use a list.count() method however i am getting the count as 0 in output which shouldn't happen. basket=[1,8 ...
Read more >List.Count works but not List.Count()?
Collections.Generic. My main problem is that I got an error trying to use the method List.Count() but it works using the property Count....
Read more >List<T>.Count Property (System.Collections.Generic)
Count is the number of elements that are actually in the List<T>. Capacity is always greater than or equal to Count. If Count...
Read more >Why is "Count" not working - Python discussion
I am not a programmer (obviously), but I can't get the result I'm looking for, which is how many times is the number...
Read more >Python List count() Method (With Examples)
The list.count() method returns the number of times an element occurs in the list. ... The count() method returns 0 if the element...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Your check is wrong. It should be
if (i < Strings.Count)
Otherwise for the third iteration of your loop (i = 2) you’ll see that 2 < 5 and your code will try to access index 2 of your list, which doesn’t exist because indexes are zero based.
Hi @kevonh
I would recommend ignoring this ticket and posting a new one yourself. Please try to make the repro as simple as possible, comments inline with the code are useful to draw attention to caveats (for example). Also, I don’t think anyone thought your question was stupid 👍