Counting the number of times a value appears in an array

前端 未结 4 1761
名媛妹妹
名媛妹妹 2020-12-18 16:27

So what\'s a good, simple algorithm to create a loop in C# where every time a certain value appears in an array it adds 1 to a counter in another array?

For example

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 16:50

    your count array has 4 fields ...

    one with the index 0, 1, 2 and 3

    so what will happen if a number like 4 (or greater) happens to be counted? yor code tries to access index 4 ... which does not exist ...

提交回复
热议问题