C# List Detailed Explanation 4

Table of contents

18.FindLast(Predicate)    

19.FindLastIndex(Int32, Int32, Predicate)    

20.FindLastIndex(Int32, Predicate)    

21.FindLastIndex(Predicate)    

22.ForEach(Action)    

23.GetEnumerator()    

24.GetHashCode()    

25.GetRange(Int32, Int32)    


C# List Detailed Explanation 1

1.Add(T),2.AddRange(IEnumerable),3.AsReadOnly(),4.BinarySearch(T),

C# List Detailed Explanation 2

5.Clear(),6.Contains(T),7.ConvertAll(Converter),8.CopyTo(Int32, T[], Int32, Int32),9.CopyTo(T[]),10.CopyTo(T[], Int32)

C# List Detailed Explanation 3

11.Equals(Object),12.Exists(Predicate),13.Find(Predicate),14.FindAll(Predicate),15.FindIndex(Int32, Int32, Predicate),16.FindIndex(Int32, Predicate),17.FindIndex(Predicate)  

C# List Detailed Explanation 4

18.FindLast(Predicate),19.FindLastIndex(Int32, Int32, Predicate),20.FindLastIndex(Int32, Predicate),21.FindLastIndex(Predicate),22.ForEach(Action),23.GetEnumerator(),24.GetHashCode(),25.GetRange(Int32, Int32) 

C# List Detailed Explanation 5

26.GetType(),27.IndexOf(T),28.IndexOf(T, Int32),29.IndexOf(T, Int32, Int32),30.Insert(Int32, T),31.InsertRange(Int32, IEnumerable),32.LastIndexOf(T),33.LastIndexOf(T, Int32),34.LastIndexOf(T, Int32, Int32)    

C# List Detailed Explanation 6

35.MemberwiseClone(),36.Remove(T),37.RemoveAll(Predicate),38.RemoveAt(Int32),39.RemoveRange(Int32, Int32),40.Reverse(),41.Reverse(Int32, Int32)    

C# List Detailed Explanation VII

42.Sort(),43.ToArray(),44.ToString(),45.TrimExcess(),46.TrueForAll(Predicate) 

C# List Detailed Explanation 1 - Xiong Siyu's Blog - CSDN Blog

C# List Detailed Explanation II - Xiong Siyu's Blog - CSDN Blog

C# List Detailed Explanation 3 - Xiong Siyu's Blog - CSDN Blog

C# List Detailed Explanation Five_Xiong Siyu's Blog - CSDN Blog

C# List Detailed Explanation 6_Xiong Siyu's Blog - CSDN Blog

C# List Detailed Explanation VII - Xiong Siyu's Blog - CSDN Blog

18.FindLast(Predicate<T>)    

Searches for elements that match the conditions defined by the specified predicate and returns the last matching element in the entire List<T>.

public T? FindLast (Predicate<T> match);

Parameters
match
Predicate<T>
The Predicate<T> delegate that defines the criteria for the elements to search for.

Returns the last element
of T
that matches the conditions defined by the specified predicate, if found; otherwise, the default value of type T.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };
            int value = list1.FindLast(x => x == 5);
            Console.WriteLine("值:{0}", value);

            Console.ReadKey();
        }
    }
}

run:

19.FindLastIndex(Int32, Int32, Predicate<T>)    

Searches for elements that match the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the List<T> that contains the specified number of elements up to the end of the specified index.

public int FindLastIndex (int startIndex, int count, Predicate<T> match);

Parameter
startIndex
Int32
The zero-based start index of the backward search.

count
Int32
The number of elements in the section to search.

match
Predicate<T>
A Predicate<T> delegate that defines the criteria for the elements to search for.

Returns
the Int32
zero-based index of the last element found that matches the condition defined by match if the element was found; otherwise -1.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };
            int index = list1.FindLastIndex(x => x == 5);
            Console.WriteLine("下标:{0}", index);

            Console.ReadKey();
        }
    }
}

run:

20.FindLastIndex(Int32, Predicate<T>)    

Searches for elements that match the conditions defined by the specified predicate and returns the zero-based index of the last occurrence in the List<T> ranging from the first element to the element at the specified index.

public int FindLastIndex (int startIndex, Predicate<T> match);

Parameter
startIndex
Int32
The zero-based start index of the backward search.

match
Predicate<T>
A Predicate<T> delegate that defines the criteria for the elements to search for.

Returns
the Int32
zero-based index of the last element found that matches the condition defined by match if the element was found; otherwise -1.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };
            int index = list1.FindLastIndex(2, x => x == 5);
            Console.WriteLine("下标:{0}", index);

            Console.ReadKey();
        }
    }
}

run:

21.FindLastIndex(Predicate<T>)    

Searches for elements that match the conditions defined by the specified predicate and returns the zero-based index of the last matching element in the entire List<T>.

public int FindLastIndex (Predicate<T> match);

Parameters
match
Predicate<T>
The Predicate<T> delegate that defines the criteria for the elements to search for.

Returns
the Int32
zero-based index of the last element found that matches the condition defined by match if the element was found; otherwise -1.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };
            int index = list1.FindLastIndex(x => x == 5);
            Console.WriteLine("下标:{0}", index);

            Console.ReadKey();
        }
    }
}

run:

22.ForEach(Action<T>)    

Performs the specified operation on each element of the List<T>.

public void ForEach (Action<T> action);

Parameters
action
Action<T>
The Action<T> delegate to execute on each element of the List<T>.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<string> names = new List<string>();
            names.Add("Bruce");
            names.Add("Alfred");
            names.Add("Tim");
            names.Add("Richard");
            names.ForEach(Print);

            Console.ReadKey();
        }

        static void Print(string s)
        {
            Console.WriteLine(s);
        }
    }
}

run:

23.GetEnumerator()    

Returns an enumerator that iterates through the List<T>.

public System.Collections.Generic.List<T>.Enumerator GetEnumerator ();

Returns
List<T>.Enumerator
for List<T>.Enumerator of List<T>.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<string> names = new List<string>();
            names.Add("Bruce");
            names.Add("Alfred");
            names.Add("Tim");
            names.Add("Richard");
            List<string>.Enumerator strings = names.GetEnumerator();

            Console.ReadKey();
        }
    }
}

24.GetHashCode()    

as the default hash function. (inherited from Object)

public virtual int GetHashCode ();

Returns the
Int32
hash code of the current object.


case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<string> names = new List<string>();
            names.Add("Bruce");
            names.Add("Alfred");
            names.Add("Tim");
            names.Add("Richard");
            int code = names.GetHashCode();
            Console.WriteLine(code);

            Console.ReadKey();
        }
    }
}

run:

25.GetRange(Int32, Int32)    

Creates a shallow copy of a range of elements in the source List<T>.

public System.Collections.Generic.List<T> GetRange (int index, int count);

Parameters
index
Int32
The zero-based List<T> index at the beginning of the range.

count
Int32
The number of elements in the range.

Returns a shallow copy of
the List<T>
range of elements in the source List<T>.

case:

using System;
using System.Collections.Generic;

namespace ListTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };
            List<int> list2 = list1.GetRange(1, 2);
            Console.WriteLine(string.Join("-", list2));

            Console.ReadKey();
        }
    }
}

run:

Chapter 4 / 7 End

Guess you like

Origin blog.csdn.net/qq_38693757/article/details/131723357