{"id":20264264,"url":"https://github.com/kawser2133/linq-and-lambda-expressions","last_synced_at":"2026-03-19T15:01:40.231Z","repository":{"id":224221399,"uuid":"762749811","full_name":"kawser2133/LINQ-and-Lambda-expressions","owner":"kawser2133","description":"LINQ (Language-Integrated Query) and Lambda expressions are powerful features in C# that allow developers to query and manipulate data in a concise and expressive manner.","archived":false,"fork":false,"pushed_at":"2024-02-29T16:10:45.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-23T13:52:41.275Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://binarybytez.com/understanding-linq-and-lambda-expressions","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kawser2133.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-24T15:34:15.000Z","updated_at":"2025-01-06T15:30:42.000Z","dependencies_parsed_at":"2024-02-29T17:30:18.981Z","dependency_job_id":"76862abd-a000-4402-aa89-4c839aef8cbb","html_url":"https://github.com/kawser2133/LINQ-and-Lambda-expressions","commit_stats":null,"previous_names":["kawser2133/linq-and-lambda-expressions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kawser2133/LINQ-and-Lambda-expressions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FLINQ-and-Lambda-expressions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FLINQ-and-Lambda-expressions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FLINQ-and-Lambda-expressions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FLINQ-and-Lambda-expressions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kawser2133","download_url":"https://codeload.github.com/kawser2133/LINQ-and-Lambda-expressions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawser2133%2FLINQ-and-Lambda-expressions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30710540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-19T05:29:31.190Z","status":"ssl_error","status_checked_at":"2026-03-19T05:28:25.821Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T11:38:57.371Z","updated_at":"2026-03-19T15:01:40.189Z","avatar_url":"https://github.com/kawser2133.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# LINQ and Lambda expressions in C#\nLINQ (Language-Integrated Query) and Lambda expressions are powerful features in C# that allow developers to query and manipulate data concisely and expressively. While both are used for similar purposes, they have distinct syntaxes and use cases. Let's explain with examples and provide multiple scenarios to illustrate the usage of LINQ and Lambda expressions in C#.\n\nYou can visit my blog post- [Understanding LINQ and Lambda Expressions in C#](https://binarybytez.com/understanding-linq-and-lambda-expressions/)\n\n## 1. LINQ (Language-Integrated Query):\n**LINQ** is a set of features in C# that enables developers to query data from different data sources using a SQL-like syntax directly within the C# language.\n\n**Syntax:** LINQ syntax consists of keywords such as from, where, select, group by, order by, etc., which resemble SQL syntax.\n```csharp\nList\u003cint\u003e numbers = new List\u003cint\u003e { 1, 2, 3, 4, 5 };\nvar evenNumbers = from num in numbers\n                  where num % 2 == 0\n                  select num;\n```\n\n## 2. Lambda Expressions:\n**Lambda expressions** are anonymous functions that allow developers to write inline delegate functions without explicitly defining a method.\n\n**Syntax:** Lambda expressions consist of the =\u003e (arrow) operator, parameters, and an expression or statement block.\n```csharp\nList\u003cint\u003e numbers = new List\u003cint\u003e { 1, 2, 3, 4, 5 };\nvar evenNumbers = numbers.Where(num =\u003e num % 2 == 0);\n```\n\n## Examples with multiple scenarios\n\n**1. Filtering a List of Objects:**\n\n**Using LINQ:**\n```csharp\nList\u003cint\u003e numbers = new List\u003cint\u003e { 1, 2, 3, 4, 5 };\nvar evenNumbers = from num in numbers\n                  where num % 2 == 0\n                  select num;\n```\n\n**Using Lambda Expression:**\n```csharp\nvar evenNumbers = numbers.Where(num =\u003e num % 2 == 0);\n```\n\n**2. Sorting a List of Objects:**\n\n**Using LINQ:**\n```csharp\nList\u003cstring\u003e fruits = new List\u003cstring\u003e { \"Apple\", \"Banana\", \"Orange\", \"Grape\" };\nvar sortedFruits = from fruit in fruits\n                   orderby fruit descending\n                   select fruit;\n```\n\n**Using Lambda Expression:**\n```csharp\nvar sortedFruits = fruits.OrderByDescending(fruit =\u003e fruit);\n```\n\n**3. Selecting Specific Properties from a List of Objects:**\n\n**Using LINQ:**\n```csharp\nList\u003cPerson\u003e people = new List\u003cPerson\u003e\n{\n    new Person { Name = \"Alice\", Age = 25 },\n    new Person { Name = \"Bob\", Age = 30 },\n    new Person { Name = \"Charlie\", Age = 28 }\n};\nvar names = from person in people\n            select person.Name;\n```\n\n**Using Lambda Expression:**\n```csharp\nvar names = people.Select(person =\u003e person.Name);\n```\n\n**4. Filtering and Projecting Data from a List of Objects:**\n\n**Using LINQ:**\n```csharp\nList\u003cPerson\u003e people = new List\u003cPerson\u003e\n{\n    new Person { Name = \"Alice\", Age = 25 },\n    new Person { Name = \"Bob\", Age = 30 },\n    new Person { Name = \"Charlie\", Age = 28 }\n};\nvar adults = from person in people\n             where person.Age \u003e= 18\n             select new { person.Name, person.Age };\n```\n\n**Using Lambda Expression:**\n```csharp\nvar adults = people.Where(person =\u003e person.Age \u003e= 18)\n                  .Select(person =\u003e new { person.Name, person.Age });\n```\n\n**5. Grouping Data from a List of Objects:**\n\n**Using LINQ:**\n```csharp\nList\u003cPerson\u003e people = new List\u003cPerson\u003e\n{\n    new Person { Name = \"Alice\", Age = 25 },\n    new Person { Name = \"Bob\", Age = 30 },\n    new Person { Name = \"Charlie\", Age = 28 }\n};\nvar ageGroups = from person in people\n               group person by person.Age \u003c 30 into youngGroup\n               select new\n               {\n                   IsYoung = youngGroup.Key,\n                   People = youngGroup.ToList()\n               };\n```\n\n**Using Lambda Expression:**\n```csharp\nvar ageGroups = people.GroupBy(person =\u003e person.Age \u003c 30)\n                     .Select(youngGroup =\u003e new\n                     {\n                         IsYoung = youngGroup.Key,\n                         People = youngGroup.ToList()\n                     });\n```\n\nThese examples demonstrate various scenarios where LINQ and Lambda expressions are used to query, filter, project, sort, and group data in C#. By understanding and mastering these features, developers can write concise and expressive code for data manipulation tasks.\n\n**Note:** The `Person` class used in these examples is assumed to have properties `Name` and `Age`.\n\nFeel free to ask if you have any questions or need further clarification! [![linkedin](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white)](https://www.linkedin.com/in/kawser2133)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawser2133%2Flinq-and-lambda-expressions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkawser2133%2Flinq-and-lambda-expressions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawser2133%2Flinq-and-lambda-expressions/lists"}