Linq in a Fast Start
do you want to start develop your query with linq ?
im gonna show you whats diffrent betweeb some commands in it , like first and first or default and so on .
be patient and read this lecture of notes . 🙂
im gonna show you whats diffrent betweeb some commands in it , like first and first or default and so on .
be patient and read this lecture of notes . 🙂
c# linq
whats diffrent First and firstOrDefault in linq command ?
if you search in integers First and query result = null then you have an exception
if you serach in Integers with FirstOrDefault and query result = null then your result is 0 , because default of Integer is 0 .
whats diffrent between first or single ?
in first query will search all content To end then returns values
and in single when query find first item , break and return it 🙂 >> when we will find a uniqe object can use to single and singleordefault .
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace linq1_1 { class Program { static void Main(string[] args) { int[] Numbers = { 1, 2, 20000, 3, 3, 3, 7, 9, 8, 5, 8, 5, 6, 11 }; int[] result = (from AliasN in Numbers select AliasN).ToArray(); //select * from numbers int[] result2 = (from Alias_N in Numbers orderby Alias_N descending select Alias_N ).ToArray(); int[] Result3 = (from Alias_N in Numbers where Alias_N > 30 select Alias_N).ToArray(); int[] Result4 = (from Alias_n in Numbers orderby Alias_n descending where Alias_n > 3 && Alias_n < 10 select Alias_n).ToArray(); int[] Result5 = (from Alias_N in Numbers where Alias_N > 100 select Alias_N).ToArray(); int[] result6 = (from alias_n in Numbers where alias_n > 10 select alias_n).ToArray(); int[] result7 = (from Alias_n in Numbers orderby Alias_n descending where Alias_n > 0 select Alias_n ).ToArray(); int ResultFirst = (from Alias_n in Numbers where Alias_n == 3 select Alias_n).First(); //here if condition is not ture then we have an exception int ResulFirstOrDefault = (from Alias_n in Numbers where Alias_n == 3 select Alias_n).FirstOrDefault(); //here if query was null then return integer default value >> 0 //int ResultSingle = (from n in Numbers // where n == 3 // select n).Single(); //int ResultSuingleOrDefault = (from n in Numbers // where n == 3 // select n).SingleOrDefault(); bool ResultCheckDuplicate = (from n in Numbers where n == 2 select n).Any(); //.any just check its have return or not with boolean return var ReturnCount = (from n in Numbers where n == 2 select n).Count(); List<String> Names = new List<string>(); Names.Add("Mohammad"); Names.Add("ghorbanI"); Names.Add("Ghorbani.dev"); var Result = (from n in Names select n).ToList(); var ResultFindChar = (from n in Names where n.ToLower().Contains("i") select n).ToList(); var ResultStrartWith = (from n in Names where n.ToLower().StartsWith("g") select n).ToList(); var ResultEndWith = (from n in Names where n.ToLower().EndsWith("m") select n).ToList(); } } public class Person { public string Name { get; set; } public string Family { get; set; } } }

linq , fast strat