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:
Here is the list of items :
Char: a
Char: b
Char: c
Char: d
Char: e
Here is the list after removing the item 'c' from the list :
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.
Result:
Here is the list of items :
Char: a
Char: b
Char: c
Char: d
Char: e
Here is the list after removing the item 'c' from the list :
Char: a
Char: b
Char: d
Char: e
need an explanation for this answer? contact us directly to get an explanation for this answer