question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List.Count does not work

See original GitHub issue

This 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrpmorriscommented, Aug 1, 2020

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.

0reactions
mrpmorriscommented, Aug 5, 2020

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 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found