remove all array elements csharp
Code Example - remove all array elements csharp
Array.Clear(myArray, 0, myArray.Length);
clear array csharp
using System;
Array.Clear(arr, 0, arr.Length);
csharp clear an array
using System;
Array.Clear(arrayToClear, 0, arrayToClear.Length);
csharp empty array
object[] emptyArray = new object[0];
how to empty an array csharp
Array.Clear(arr, 0, arr.Length);
remove index from array csharp
//You can't change length of array in c#
//But you change Lists in c#
int foos = new List<int>(array);
foos.RemoveAt(index);
array = foos.ToArray();
how to remove an element from an array csharp
static void Main(string[] args)
{
int[] arr = { 1, 3, 4, 9, 2 };
int numToRemove = 3;
var numIndex = arr.Where(x=>x ==numToRemove);
if(numIndex.Any()){
var idx = Array.IndexOf(arr,numToRemove);
var remove = arr.Remove(idx);
}
}
remove from array csharp
// easier to convert to list and remove
int[] arrayToConvert = new int[] {1, 2, 3, 4};
List<int> converted = new List<int>(arrayToConvert);
converted.RemoveAt(0);
// do this if you cant use list instead of array