The difference between remove (), RemoveAt (), RemoveRange (), RemoveAll () in C #. Net list<t>,list<t> Delete Rollup

Source: Internet
Author: User

Remove (), RemoveAt (), RemoveRange (), RemoveAll () are the main methods of removing list<t>. Here are a few ways to use and pay attention.

We take list<string> for example

var New list<string"aa" "ba""cc " " DD " " ee " " FF " };

Remove () removes the first item that is matched to the list, the parameter is T in List<t>, the return type is bool, the successful delete returns True, or the return false is not found. For example:

var rt =  Strlist.remove ("aa");

Second, RemoveAt () deletes an entry for the specified index. The parameter is int, which represents the index. The return type is void. For example:

Strlist.removeat (0);

RemoveRange () Deletes the entry for the specified index segment, the first parameter is the starting index of the deletion, and the second parameter is the number of deletions. The range type is void. For example:

Strlist.removerange (02);

Iv. RemoveAll () Removes all occurrences of the item, and the parameter is a predicate<t> delegate that defines the condition to be met by the element to be deleted. The return type is int, which indicates the number of deletions. For example:

// Lambda-expression var rt = Strlist.removeall (J=>j.contains ("a")); // Custom Conditions Private Static BOOL Isdel (string  str) {    return str. Contains ("a");} var rt = Strlist.removeall (Isdel);

C #. Net list<t> The difference between remove (), RemoveAt (), RemoveRange (), RemoveAll (),list<t> Delete Rollup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.