Removing all four-letter words in the list - CSharp Collection

CSharp examples for Collection:List

Description

Removing all four-letter words in the list

Demo Code


using System;// w ww .  j  ava 2 s . c o m
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<int> numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
        int[] numArray = numbers.ToArray();
        List<string> words = new List<string> { "one", "two", "three", "four", "five" };

        int numElementsRemoved = words.RemoveAll(word => word.Length == 4);
        Console.Write("\tWords remaining after removal: ");
        words.ForEach(word => Console.Write("{0}, ", word));
    }
}

Result


Related Tutorials