[Note] Delete Array array elements specified

[Note] Delete Array array elements specified


Foreword

How to remove the record of this article Array array elements specified!

Array want to remove a particular element of the array, but found that because of the Array class, there is no similar methods can be used Remove XD

As shown below:

Array

Array members about the investigation, and did not find a common method Remove method, but in the .NET Framework 2.0 Array class has a real do IList, ICollection and IEnumerable generic interface

Using LINQ


int[] myNumbers = { 1, 30, 26, 53, 97, };

int myRemoveNum = 53;

myNumbers = myNumbers.Where(val => val != myRemoveNum).ToArray();

.NET Framework 3.5

namespace:System.Linq

Through Enumerable.Where Way to find out input data eligible projects.

Do not use LINQ


int[] myNumbers = { 1, 30, 26, 53, 97, };

int myRemoveNum = 53;

myNumbers = Array.FindAll(myNumbers, val => val != myRemoveNum).ToArray();

.NET Framework 2.0

Get all the elements qualifying through Array.FindAll generic method.

It has been assumed that the above elements are used without repeated, but if there are array elements may repeat the words

Can be found in line with the first data item through Array.IndexOf method, reference may be made here.

reference

How to delete an element from an array in C#

Array members

Enumerable.Where

Array.FindAll

Original: Large column  [Note] Delete Array array elements specified


Guess you like

Origin www.cnblogs.com/chinatrump/p/11490904.html