Text version of the video
http://csharp-video-tutorials.blogspo...
Slides
http://csharp-video-tutorials.blogspo...
LINQ Tutorial - All Text Articles & Slides
http://csharp-video-tutorials.blogspo...
LINQ Tutorial Playlist
https://www.youtube.com/playlist?list...
Dot Net, SQL, Angular, JavaScript, jQuery and Bootstrap complete courses
https://www.youtube.com/user/kudvenka...
The following operators belong to Generation Operators category
Range
Repeat
Empty
Range operator generates a sequence of integers within a specified range. This method has 2 integer parameters. The start parameter specifies the integer to start with and the count parameter specifies the number of sequential integers to generate.
For example to print the first 10 even numbers without using LINQ, we would use a for loop as shown below.
for (int i = 1; i [= 10; i++)
{ if (i % 2 == 0) { Console.WriteLine(i); }
}
To achieve the same using LINQ, we can use Range method as shown below.
var evenNumbers = Enumerable.Range(1, 10).Where(x =] x % 2 == 0);
foreach (int i in evenNumbers)
{ Console.WriteLine(i);
}
Repeat operator is used to generate a sequence that contains one repeated value.
For example the following code returns a string sequence that contains 5 "Hello" string objects in it.
var result = Enumerable.Repeat("Hello", 5);
foreach (var v in result)
{ Console.WriteLine(v);
}
Empty operator returns an empty sequence of the specified type. For example
Enumerable.Empty[int]() - Returns an empty IEnumerable[int]
Enumerable.Empty[string]() - Returns an empty IEnumerable[string]
The question that comes to our mind is, what is the use of Empty() method. Here is an example where we could use Empty() method
There may be scenarios where our application calls a method in a third party application that returns IEnumerable[int]. There may be a situation where the third party method returns null. For the purpose of this example, let us assume the third party method is similar to GetIntegerSequence().
A NULL reference exception will be thrown if we run the following code
class Program
{ public static void Main() { IEnumerable[int] result = GetIntegerSequence(); foreach (var v in result) { Console.WriteLine(v); } } private static IEnumerable[int] GetIntegerSequence() { return null; }
}
One way to fix this is to use NULL check before looping thru the items in the result as shown below.
class Program
{ public static void Main() { IEnumerable[int] result = GetIntegerSequence(); if (result != null) { foreach (var v in result) { Console.WriteLine(v); } } } private static IEnumerable[int] GetIntegerSequence() { return null; }
}
The other way to fix it, is by using Empty() linq method as shown below. Here we are using NULL-COALESCING operator that checks if the GetIntegerSequence() method returns NULL, in which case the result variable is initialized with an empty IEnumerable[int].
class Program
{ public static void Main() { IEnumerable[int] result = GetIntegerSequence() ?? Enumerable.Empty[int](); foreach (var v in result) { Console.WriteLine(v); } } private static IEnumerable[int] GetIntegerSequence() { return null; }
}
examples of idioms Part 28 Generation Operators in LINQ | |
| 88 Likes | 88 Dislikes |
| 24,534 views views | 524K followers |
| Education | Upload TimePublished on 12 Aug 2014 |
Related keywords
asp.net core docker,wcf vs web api,ado.net core,sql server management studio,webkinz,webadvisor,craigslist nj,wcf one piece,asp.net core 3,ajax players,examples of personification,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,services angular,ajax ontario,example resume,asp.net mvc tutorial,examples of alliteration,asp.net cos'è,csharp assembly,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,asp.net zero,csharp foreach,server memes,sql date format,services online,chase,examples of culture,serverless architecture,server resume,wcf c#,server books,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,ajax deadpool,server jobs,cvs,website,mvc tutorial,costco hours,wcf service application,examples of proteins,tutorialspoint spring,serverless,wcf soap,wcf cat,cool math games,wcf test client,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,mvconnect,cunyfirst,asp.net guida,wcf nba,csharp download,wcfi foundation,csharp online,wcf authentication,tutorials near me,http://asp.net,server 2019,chernobyl,ado.net descargar,web of dreams,serverminer,ajax cleaner,ado.net visual studio 2019,webassign,ado.net vs entity framework,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,mvc architecture,http://ado.net,asp.net core mvc,ajax soccer,server hosting,examples of parasitism,wcfi,ajax dish soap,capital one,server rack,tutorialspoint html,csharp interface,craigslist,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,tutorialspoint python 3,sql developer,webster,services transmission company sas,sql group by,asp.net core signalr,services manager,mvc framework,ajax paving,mvc near me,examples of irony,examples of figurative language,tutorialspoint spring boot,mvc map,csharp online compiler,asp.net download,sql between,ado.net c# pdf,services tag dell,wcf 2019 nba,csharp switch,ado.net ventajas y desventajas,csharpstar,wcf tutorial,examples of adjectives,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,central park 5,csharp string format,ado.net c#,asp.net core github,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,server error in '/' application,services windows,asp.net core 3.0,sql injection,tutorialspoint c#,wcf ria services,calculator,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,sqlyog,asp.net core 3 release date,sql server,server job description,tutorials by a,servicenow,examples of lipids,webcam,mvc hours,webmd symptom,csharp array,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,cheap flights,webcrims,asp.net core hosting,services sas,examples of metaphors,tutorialspoint java,tutorialspoint java compiler,examples of adverbs,webmd,csharp to json,college football,ado.net dataset,csharp dictionary,examples of tone,cnn,website builder,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,example synonym,tutorialspoint spark,mvc nj,ado.net oracle,asp.net core download,csharp to vb.net,webster bank,webstaurant,examples of resignation letters,tutorialsystems,ajax post,services fms publish announcement,services.msc no abre,ajax jersey,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,century 21,examples of carbohydrates,services consultores,services consulting,mvcsd,services.msc,mvcsc,ado.net pdf,asp.net core configuration,ajax marvel,sql update,asp.net tutorial,mvc medical,example of mutualism,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,ado.net entity data model visual studio 2017,chase online,wcf api,costco,server jobs near me,webex,sql meaning,sql tutorial,sql commands,ado.net entity framework,ajax tavern,example cover letter,tutorialsteacher,ajax javascript,services desk,ajax greek,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,mvcu,example of commensalism,asp.net core middleware,wcf web service,mvc webadvisor,web store,mvcc,webmail,mvci,mvctc,
Không có nhận xét nào:
Đăng nhận xét