{"id":66117,"date":"2022-04-03T09:14:48","date_gmt":"2022-04-03T07:14:48","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=66117"},"modified":"2022-04-15T07:43:49","modified_gmt":"2022-04-15T05:43:49","slug":"linq-csharp-basic-concepts","status":"publish","type":"post","link":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/","title":{"rendered":"LINQ Basic Concepts in C#"},"content":{"rendered":"<p>In this article, we are going to learn about LINQ (Language Integrated Query) in C#. We are going to see why we should use LINQ in our codebase, and different ways to implement and execute LINQ queries. Furthermore, we will explore some of the frequently used LINQ queries.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-linq\/LINQBasicDemo\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let\u2019s dive in.<\/p>\n<h2>What is LINQ?<\/h2>\n<p>LINQ is a uniform query language, introduced with .NET 3.5 that we can use to retrieve data from different data sources. These data sources include the collection of objects, relational databases, ADO.NET datasets, XML files, etc.<\/p>\n<h2>Different Steps of a LINQ Query Operation<\/h2>\n<p>Let&#8217;s explore the three distinct steps of a LINQ query operation:<\/p>\n<ul>\n<li>Obtain the data source<\/li>\n<li>Create the query<\/li>\n<li>Execute the query<\/li>\n<\/ul>\n<h3>Obtain the Data Source<\/h3>\n<p>A valid LINQ data source must support the <code>IEnumerable&lt;T&gt;<\/code> interface or an interface that inherits from it.<\/p>\n<p>So, let\u2019s define a simple data source:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var studentIds = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };<\/code><\/p>\n<p>The <code>studentIds<\/code> is an array and it supports the <code>IEnumerable&lt;T&gt;<\/code> interface.\u00a0<\/p>\n<p><strong>Types that support<\/strong> <code>IEnumerable&lt;T&gt;<\/code><strong> or a derived interface<\/strong> (<code>IQueryable&lt;T&gt;<\/code>)<strong> are called<\/strong> <strong>queryable types<\/strong>. A queryable type can directly be applied as a LINQ data source. However, if the data source is not represented in memory as a queryable type, we have to use <code>LINQ<\/code> providers to load it to a queryable form.<\/p>\n<h3>Create the Query<\/h3>\n<p>A query specifies what information we want to retrieve from the data source.\u00a0<\/p>\n<p>To create a query, we have to import LINQ into our code:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using System.Linq;<\/code><\/p>\n<p>Let&#8217;s now define the query:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var studentsWithEvenIds =\r\n    from studentId in studentIds\r\n\u00a0   where (studentId % 2) == 0\r\n\u00a0\u00a0\u00a0\u00a0select studentId;<\/pre>\n<p>Here, we are returning the <code>IEnumerable&lt;int&gt;<\/code> collection named <code>studentsWithEvenIds<\/code> . It holds all the even-numbered student ids.<\/p>\n<p>The query expression has three clauses. The <code>from<\/code>, <code>where<\/code> and <code>select<\/code>. The <code>from<\/code> clause describes the data source. The <code>where<\/code> clause applies filters and the <code>select<\/code> clause produces the result of the query by shaping the data.<\/p>\n<p>We have to pay attention to one important fact &#8211; we are not executing the query yet.<\/p>\n<h3>Execute the Query<\/h3>\n<p>There are two ways to execute a LINQ query:<\/p>\n<ul>\n<li>Deferred Execution<\/li>\n<li>Immediate Execution<\/li>\n<\/ul>\n<h3><strong>Deferred Execution<\/strong><\/h3>\n<p>We differ the actual execution of our previous query until we iterate over it using a <code>foreach<\/code> statement. This concept is called <strong>deferred execution <\/strong>or <strong>lazy loading<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">foreach (int studentId in studentsWithEvenIds)\r\n{\r\n\u00a0\u00a0\u00a0 Console.Write(\"Student Id {0} which is even.\", studentId);\r\n}<\/pre>\n<h3>Immediate Execution<\/h3>\n<p>Immediate execution is completely the opposite of deferred execution. Here, we execute our query and get the result immediately. Aggregate functions such as <code>Count<\/code>, <code>Average<\/code>, <code>Min<\/code>, <code>Max<\/code>, <code>Sum,<\/code> and element operators such as <code>First<\/code>, <code>Last<\/code>, <code>SingleToList<\/code>, <code>ToArray<\/code>, <code>ToDictionary<\/code> are some examples.<\/p>\n<p>We are going to see these functions in action in the rest of the article.<\/p>\n<h2>Basic Ways to Write LINQ Queries<\/h2>\n<p>There are two basic ways to write LINQ queries:<\/p>\n<ul>\n<li>Query Syntax<\/li>\n<li>Method Syntax<\/li>\n<\/ul>\n<h3>Query Syntax<\/h3>\n<p>To start with our example, we are going to define a method that returns our data source:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">static IQueryable&lt;Student&gt; GetStudentsFromDb()\r\n{\r\n    return new[] {  \r\n        new Student() { StudentID = 1, StudentName = \"John Nigel\", Mark = 73, City =\"NYC\"} ,\r\n        new Student() { StudentID = 2, StudentName = \"Alex Roma\",  Mark = 51 , City =\"CA\"} ,\r\n        new Student() { StudentID = 3, StudentName = \"Noha Shamil\",  Mark = 88 , City =\"CA\"} ,\r\n        new Student() { StudentID = 4, StudentName = \"James Palatte\" , Mark = 60, City =\"NYC\"} ,\r\n        new Student() { StudentID = 5, StudentName = \"Ron Jenova\" , Mark = 85 , City =\"NYC\"} \r\n    }.AsQueryable();\r\n}<\/pre>\n<p>We are going to use a LINQ query syntax to find all the students with <code>Mark<\/code> higher than 80:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var studentList = GetStudentsFromDb();\r\nvar highPerformingStudents = from student in studentList\r\n    where student.Mark &gt; 80\r\n    select student;<\/pre>\n<p>The query syntax starts with a <code>from<\/code> clause. Thereafter, we can use any standard query operator to join, group, or filter the result. In this example, we use <code>where<\/code> as the standard query operator. The query syntax ends with either <code>a select<\/code> or a\u00a0<code>groupBy<\/code> clause.<\/p>\n<h3>Method Syntax<\/h3>\n<p>Method syntax use extension methods provided in the <code>Enumerable<\/code> and <code>Queryable<\/code> classes.<\/p>\n<p>To see that syntax in action, let\u2019s create another query:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var highPerformingStudents = studentList.Where(s =&gt; s.Mark &gt; 80);<\/code><\/p>\n<p>In this example, we are using the <code>Where()<\/code> extension method and provide a lambda expression <code>s =&gt; s.Mark &gt; 80<\/code> as an argument.<\/p>\n<h2>Lambda Expressions With LINQ<\/h2>\n<p>In LINQ, we use lambda expressions in a convenient way to define anonymous functions. It is possible to pass a lambda expression as a variable or as a parameter to a method call. However, in many LINQ methods, lambda expressions are used as a parameter. As a result, it makes the syntax short, and precise. Its scope is limited to where it is used as an expression. Therefore, we are not able to reuse it afterward.<\/p>\n<p>To see Lambda expression in play, let&#8217;s create a query:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var firstStudent = studentList.Select(x =&gt; x.StudentName);<\/code><\/p>\n<p>The expression <code>x =&gt; x.StudentName<\/code> is a lambda expression.\u00a0 <code>x<\/code> here is an input parameter to the anonymous function representing each object inside the collection.<\/p>\n<h2>Frequently Used LINQ Methods\u00a0<\/h2>\n<p>Since we&#8217;ve already seen the <code>Where<\/code> method in action, let&#8217;s take a look at the other top LINQ methods we use in our everyday C# programming.\u00a0<\/p>\n<h3>Sorting: OrderBy, OrderByDecending<\/h3>\n<p>We can use the <code>OrderBy()<\/code> method to sort a collection in ascending order based on the selected property:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var selectStudentsWithOrderById = studentList.OrderBy(x =&gt; x.StudentID);<\/code><\/p>\n<p>Similar to <code>OrderBy()<\/code> method, the <code>OrderByDescending()<\/code> method sorts the collection using the <code>StudentID<\/code> property in descending order:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var selectStudentsWithOrderByDescendingId = studentList.OrderByDescending(x =&gt; x.StudentID);<\/code><\/p>\n<h3>Projection: Select<\/h3>\n<p>We use the <code>Select<\/code> method to project each element of a sequence into a new form:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var studentsIdentified = studentList.Where(c =&gt; c.StudentName == name)\r\n    .Select(stu =&gt; new Student {StudentName = stu.StudentName , Mark = stu.Mark});<\/pre>\n<p>Here, we filter only the students with the required name and then use the projection <code>Select<\/code> method to return students with only <code>StudentName<\/code> and <code>Mark<\/code> properties populated. This way, we can easily extract only the required information from our objects.<\/p>\n<h3>Grouping: GroupBy<\/h3>\n<p>We can use the <code>GroupBy()<\/code> method to group elements based on the specified key selector function. In this example, we are using <code>City<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var studentListGroupByCity = studentList.GroupBy(x =&gt; x.City);<\/code><\/p>\n<p>One thing to mention. All the previous methods (Where, OrderBy, OrderByDescending, Select, GroupBy) return collection as a result. So, in order to use all the data inside the collection, we have to iterate over it.<\/p>\n<h3>All, Any, Contains<\/h3>\n<p>We can use <code>All()<\/code> to determine whether <strong>all elements<\/strong> of a sequence satisfy a condition:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var hasAllStudentsPassed = studentList.All(x =&gt; x.Mark &gt; 50);<\/code><\/p>\n<p>Similarly, we can use <code>Any()<\/code> to determine if <strong>any element<\/strong> of a sequence exists or satisfies a condition:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var hasAnyStudentGotDistinction = studentList.Any(x =&gt; x.Mark &gt; 86);<\/code><\/p>\n<p>The <code>Contains()<\/code> method determines whether a sequence or a collection contains a specified element:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var studentContainsId = studentList.Contains(new Student { StudentName = \"Noha Shamil\"}, new StudentNameComparer());<\/code><\/p>\n<h3>Partitioning: Skip, Take<\/h3>\n<p><code>Skip()<\/code> will bypass a specified number of elements in a sequence and return the remaining elements:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var skipStuentsUptoIndexTwo = studentList.Skip(2);<\/code><\/p>\n<p><code>Take()<\/code> will return a specified number of elements from the first element in a sequence:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var takeStudentsUptoIndexTwo = studentList.Take(2);<\/code><\/p>\n<h3>Aggregation: Count, Max, Min, Sum, Average<\/h3>\n<p>Applying the <code>Sum()<\/code> method on the property <code>Mark<\/code> will give the summation of all marks:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var\u00a0sumOfMarks = studentList.Sum(x =&gt; x.Mark);<\/code><\/p>\n<p>We can use the <code>Count()<\/code> method to return the number of students with a score higher than 65:\u00a0<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var\u00a0countOfStudents = studentList.Count(x =&gt; x.Mark &gt; 65);<\/code><\/p>\n<p><code>Max()<\/code> will display the highest <code>Mark<\/code> scored by a student from the collection:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var\u00a0maxMarks = studentList.Max(x =&gt; x.Mark);<\/code><\/p>\n<p><code>Min()<\/code> will display the lowest marks scored by a student from the collection:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var\u00a0minMarks = studentList.Min(x =&gt; x.Mark);<\/code><\/p>\n<p>We can use <code>Average()<\/code> to compute the average of a sequence of numerical values:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var avgMarks = studentList.Average(x =&gt; x.Mark);<\/code><\/p>\n<h3>Elements: First, FirstOrDefault, Single, SingleOrDefault<\/h3>\n<p><code>First()<\/code> returns the first element in the list that satisfies the <code>predicate<\/code> function. However, if the input sequence is null it throws the <code>ArgumentNullException<\/code> and if there&#8217;s no element for a condition it throws <code>InvalidOperationException<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var firstStudent = studentList.First(x =&gt; x.StudentID % 2 == 0);<\/code><\/p>\n<p><code>FirstOrDefault()<\/code> works similarly to the <code>First()<\/code> method for positive use cases. If there&#8217;s no element found it will return <code>null<\/code> for reference types and a default value for the value types:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var firstOrDefaultStudent = studentList.FirstOrDefault(x =&gt; x.StudentID == 1);<br \/>\n<\/code><\/p>\n<p><code>Single()<\/code> method returns only one element in the collection after satisfying the condition. It also throws the same exceptions as the <code>First()<\/code> method if the source or predicate is null, or if more than one element satisfies the condition of the predicate:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var singleStudent = studentList.Single(x =&gt; x.StudentID == 1);<\/code><\/p>\n<p><code>SingleOrDefault()<\/code> method works similar to <code>Single()<\/code> when we find the required element. But if we can&#8217;t find an element that meets our condition, the method will return <code>null<\/code>\u00a0for reference type or the default value for value types:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var singleOrDefaultStudent = studentList.SingleOrDefault(x =&gt; x.StudentID  == 1);<\/code><\/p>\n<h2>Advantages and Disadvantages of Using LINQ<\/h2>\n<p>Let&#8217;s check some advantages of using LINQ:<\/p>\n<ul>\n<li>Improves code readability<\/li>\n<li>Provides compile-time object type-checking<\/li>\n<li>Provides IntelliSense support for generic collection<\/li>\n<li>LINQ queries can be reused<\/li>\n<li>Provides in-built methods to write less code and expedite development<\/li>\n<li>Provides common query syntax for various data sources<\/li>\n<\/ul>\n<p>There are also disadvantages of using LINQ:<\/p>\n<ul>\n<li>Difficult to write complex queries as SQL<\/li>\n<li>Performance degradation if queries are not written accurately<\/li>\n<li>Require to recompile, and redeploy every time a change is made to the query<\/li>\n<li>Doesn&#8217;t take full advantage of SQL features such as cached execution plan for stored procedure<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this article, we&#8217;ve learned about LINQ in <a href=\"https:\/\/code-maze.com\/csharp-back-to-basics\/\" target=\"_blank\" rel=\"noopener\">C#<\/a>, the three parts of query operations, different ways to implement LINQ queries, and how to use LINQ queries in our codebase. So, this would be enough to get you started with using LINQ in your projects.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to learn about LINQ (Language Integrated Query) in C#. We are going to see why we should use LINQ in our codebase, and different ways to implement and execute LINQ queries. Furthermore, we will explore some of the frequently used LINQ queries. Let\u2019s dive in. What is LINQ? LINQ [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[1187,209,1182,1183,544,1188,1189,1186,1184,1185,1190,1191],"class_list":["post-66117","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-average","tag-basics","tag-first","tag-firstordefault","tag-linq","tag-max","tag-min","tag-select","tag-single","tag-singleordefault","tag-skip","tag-take","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LINQ Basic Concepts in C# - Code Maze C# LINQ<\/title>\n<meta name=\"description\" content=\"In this article, we are going to learn about LINQ basic concepts in C#. We will use different syntax with different methods\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LINQ Basic Concepts in C# - Code Maze C# LINQ\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to learn about LINQ basic concepts in C#. We will use different syntax with different methods\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-03T07:14:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-15T05:43:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"LINQ Basic Concepts in C#\",\"datePublished\":\"2022-04-03T07:14:48+00:00\",\"dateModified\":\"2022-04-15T05:43:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\"},\"wordCount\":1283,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"Average\",\"Basics\",\"First\",\"FirstOrDefault\",\"LINQ\",\"Max\",\"Min\",\"Select\",\"Single\",\"SingleOrDefault\",\"Skip\",\"Take\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\",\"url\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\",\"name\":\"LINQ Basic Concepts in C# - Code Maze C# LINQ\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-04-03T07:14:48+00:00\",\"dateModified\":\"2022-04-15T05:43:49+00:00\",\"description\":\"In this article, we are going to learn about LINQ basic concepts in C#. We will use different syntax with different methods\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LINQ Basic Concepts in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LINQ Basic Concepts in C# - Code Maze C# LINQ","description":"In this article, we are going to learn about LINQ basic concepts in C#. We will use different syntax with different methods","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/","og_locale":"en_US","og_type":"article","og_title":"LINQ Basic Concepts in C# - Code Maze C# LINQ","og_description":"In this article, we are going to learn about LINQ basic concepts in C#. We will use different syntax with different methods","og_url":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/","og_site_name":"Code Maze","article_published_time":"2022-04-03T07:14:48+00:00","article_modified_time":"2022-04-15T05:43:49+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"LINQ Basic Concepts in C#","datePublished":"2022-04-03T07:14:48+00:00","dateModified":"2022-04-15T05:43:49+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/"},"wordCount":1283,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["Average","Basics","First","FirstOrDefault","LINQ","Max","Min","Select","Single","SingleOrDefault","Skip","Take"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/","url":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/","name":"LINQ Basic Concepts in C# - Code Maze C# LINQ","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-04-03T07:14:48+00:00","dateModified":"2022-04-15T05:43:49+00:00","description":"In this article, we are going to learn about LINQ basic concepts in C#. We will use different syntax with different methods","breadcrumb":{"@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/linq-csharp-basic-concepts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/linq-csharp-basic-concepts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"LINQ Basic Concepts in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=66117"}],"version-history":[{"count":5,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66117\/revisions"}],"predecessor-version":[{"id":69403,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66117\/revisions\/69403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=66117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=66117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=66117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}