// list of states with name smaller than 9 characters
IEnumerable<string> smallStates = states
.Where(n => n.Length < 9)
.Select(n => n);
foreach (string name in smallStates) Console.WriteLine("{0}", name);
//Other Syntax
smallStates = from n in states
where n.Length < 9
select n;
foreach (string name in smallStates)Console.WriteLine("{0}", name);
// Both result in same output
2012-07-18 23:51
following is two such syntaxes widely used.
var allstates = from n in states select n;
var allstates2 = states.Select(s => s);
2012-07-18 23:55
Notice both syntaxes are equally usable for an aggregate "First()"
string youState = states.Where(p => p.StartsWith("M")).First();
string youState2 = (from k in states where (k.StartsWith("M")) select k).First();
2012-07-18 23:58
List<string> youStates = states.Where(p => p.StartsWith("M")).ToList();
List<string> youStates2 = (from k in states where (k.StartsWith("M")) select k).ToList();
2012-07-19 00:02
This blog is frozen. No new comments or edits allowed.
string[] states = {
"Bengal","Daman and diu","Goa", "Haryana","Kashmir", "Kerala","Laccadives","NCT" , "Rajasthan", "Andhra Pradesh" , "Arunāchal Pradesh", "Assam","Bihār","Chhattīsgarh" , "Gujarāt","Himāchal Pradesh", "Jharkhand", "Karnātaka","Madhya Pradesh","Mahārāshtra" ,"Manipur","Meghālaya", "Mizoram","Nāgāland","Odisha", "Punjab","Sikkim", "Tamil Nādu" , "Tripura", "Andaman and Nicobar Islands","Chandīgarh", "Dādra and Nagar Haveli" , "Puducherry", "Uttar Pradesh", "Uttarakhand" };
// list of states with name smaller than 9 characters
IEnumerable<string> smallStates = states .Where(n => n.Length < 9) .Select(n => n); foreach (string name in smallStates) Console.WriteLine("{0}", name); //Other Syntax smallStates = from n in states where n.Length < 9 select n; foreach (string name in smallStates)Console.WriteLine("{0}", name); // Both result in same output