Answers for "get elements in index range c#"

C#
1

list index out of range C#

// Copy array to temporary array
for (int index=0; index < lines.Length; index++)
{
    // System.ArgumentOutOfRangeException was unhandled
    // Index was out of range. Must be non-negative and less than the size of the collection.
    if (lines[index].Length >= 0)
    {
        temp[index] = lines[index];
    }
 }
 // Check for duplicates. If duplicate ignore if non-duplicate add to list.
 foreach (string line in temp)
 {
   if (!newlist.Contains(line))
   {
       newlist.Add(line);
   }
 }
 lstBox.Items.Clear();
 foreach (string strNewLine in newlist)
 {
    lstBox.Items.Add(strNewLine);
 }
Posted by: Guest on November-22-2020
0

range index c#

var array = new int[] { 1, 2, 3, 4, 5 };
var slice1 = array[2..^1];    // 3, 4 
var slice2 = array[..^3];     // 1, 2
var slice3 = array[2..];      // 3, 4, 5
var slice4 = array[..];       // 1, 2, 3, 4, 5
Posted by: Guest on September-20-2021

C# Answers by Framework

Browse Popular Code Answers by Language