Skip to content

Commit 18b20a1

Browse files
authored
Fix IList.Insert example to handle index == Count case (#12285)
1 parent 7409565 commit 18b20a1

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

  • snippets
    • csharp/System.Collections/IList/Overview
    • visualbasic/System.Collections/IList/Overview

snippets/csharp/System.Collections/IList/Overview/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public int IndexOf(object value)
103103

104104
public void Insert(int index, object value)
105105
{
106-
if ((_count + 1 <= _contents.Length) && (index < Count) && (index >= 0))
106+
if ((_count + 1 <= _contents.Length) && (index <= Count) && (index >= 0))
107107
{
108108
_count++;
109109

snippets/visualbasic/System.Collections/IList/Overview/Program.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Public Class SimpleList
9090

9191
Public Sub Insert(ByVal index As Integer, ByVal value As Object) Implements IList.Insert
9292

93-
If _count + 1 <= _contents.Length AndAlso index < Count AndAlso index >= 0 Then
93+
If _count + 1 <= _contents.Length AndAlso index <= Count AndAlso index >= 0 Then
9494
_count += 1
9595

9696
For i As Integer = Count - 1 To index Step -1

0 commit comments

Comments
 (0)