Tech Study

Write a program in C# to Remove Items from List using remove function by passing object in LINQ Query

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
class LinqExercise
{
    static void Main(string[] args)
    {
 
        List<string> list = new List<string>();
        list.Add("a");
        list.Add("b");
        list.Add("c");
        list.Add("d");
        list.Add("e");
 
        var _result1 = from y in list
                       select y;
        Console.Write("Here is the list of items : \n");
        foreach (var tchar in _result1)
        {
            Console.WriteLine("Char: {0} ", tchar);
        }
 
        string newstr = list.FirstOrDefault(n => n == "c");
        list.Remove(newstr);
 
 
        var _result = from z in list
                      select z;
        Console.Write("\nHere is the list after removing the item 'c' from the list : \n");
        foreach (var c in _result)
        {
            Console.WriteLine("Char: {0} ", c);
        }
 
        Console.ReadLine();
    }
}

Result

Write a program in C# to Remove Items from List using remove function by passing object in LINQ Query
Write a program in C# to Remove Items from List using remove function by passing object in LINQ Query

TaggedWrite a program in C# to Remove Items from List using remove function by passing object in LINQ Query

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more