C# Keywords Tutorial Part 99: where (2024)

C# Keywords Tutorial Part 99: where (1)

  • Report this article

Amr Saafan C# Keywords Tutorial Part 99: where (2)

Amr Saafan

Founder | CTO | Software Architect & Consultant | Engineering Manager | Project Manager | Product Owner | +27K Followers | Now Hiring!

Published Apr 21, 2023

+ Follow

Popular computer language C# is used to create a variety of applications, including desktop software and web apps. The “where” keyword, which is used to filter data based on specific criteria, is one of the language’s strong features. In this article, we’ll go over the “where” keyword in depth and give several C# code examples to demonstrate how to utilize it.

The “where” Keyword in C#

The “where” keyword is used in C# to specify a set of conditions that must be met by elements in a collection. This keyword is typically used in conjunction with the “IEnumerable” interface to filter data based on a specific condition.

Here’s an example of how the “where” keyword can be used in C#:

var numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };var evenNumbers = numbers.Where(n => n % 2 == 0); 

In this example, we’ve declared a list of numbers, and we’re using the “where” keyword to filter out all the even numbers from the list. The condition we’ve specified is that the number must be divisible by 2 with no remainder.

Recommended by LinkedIn

Taking Advantage of the New Language Features in .NET 7 VService IT Solutions 1 year ago
New Course: Data Analytics with Observable Bill Shander 7 months ago
Elevating JavaScript with Closures: A Journey into… Laurence Svekis ✔ 6 months ago

Using the “where” Keyword with LINQ

The “where” keyword is also commonly used with Language Integrated Query (LINQ) in C#. LINQ allows developers to perform complex queries on data sources using a simple syntax, and the “where” keyword is often used to filter data.

Here’s an example of how the “where” keyword can be used with LINQ in C#:

var books = new List<Book>{ new Book { Title = "The Great Gatsby", Author = "F. Scott Fitzgerald", Year = 1925 }, new Book { Title = "To Kill a Mockingbird", Author = "Harper Lee", Year = 1960 }, new Book { Title = "1984", Author = "George Orwell", Year = 1949 }, new Book { Title = "The Catcher in the Rye", Author = "J.D. Salinger", Year = 1951 }};var modernBooks = from book in books where book.Year > 1950 select book; 

In this example, we’ve created a list of books and filtered away all the books that were released before 1950 using the “where” keyword. The query has been specified using the LINQ syntax, which is clearer and shorter than conventional loops.

Like
Comment

1

To view or add a comment, sign in

More articles by this author

No more previous content

  • Implementing Clickjacking Defense Techniques in JavaScript Sep 15, 2024
  • AS Keyword in SQL Server Sep 12, 2024
  • Salesforce vs. Dynamics: Which CRM Solution Is Best for Your Business? Sep 11, 2024
  • Scaling React Apps with Reusable List Components Sep 10, 2024
  • How to Use the SQL Server ANY Keyword for Flexible Querying Sep 9, 2024
  • Advanced Apex Techniques for Salesforce Developers Sep 4, 2024
  • Terraform Your Way to High Availability: Deploying a Full Stack AWS Architecture Sep 3, 2024
  • 10 Reasons TypeScript is Transforming How We Build Web Apps Sep 2, 2024
  • Django Request Life Cycle Explained Sep 1, 2024
  • C# .NET Exception Handling: Why You Should Avoid Using throw ex in Catch Blocks Aug 31, 2024

No more next content

See all

Sign in

Stay updated on your professional world

Sign in

By clicking Continue to join or sign in, you agree to LinkedIn’s User Agreement, Privacy Policy, and Cookie Policy.

New to LinkedIn? Join now

Insights from the community

  • Language Integrated Query (LINQ) How do you control LINQ query execution?
  • Web Applications How do you use web application APIs to visualize data?
  • Software Development How do you choose between JSON and XML for data exchange?
  • Software Development How do you measure the performance of a parallel LINQ query?
  • Language Integrated Query (LINQ) How do you change the execution context of a LINQ query expression?
  • Language Integrated Query (LINQ) How do you compare and contrast different LINQ providers and extensions?
  • Web Development How can you use Sequelize ORM in Node.js?
  • Computer Science What are the best ways to prevent SQL injections in web design?
  • Data Entry How do you handle complex or nested data structures with JSON?
  • Data Processing What are the advantages and disadvantages of using JSON vs XML?

Others also viewed

  • How To Optimize An SQL query in a Django application? Amr Saafan 1y
  • Out of the Shadows: Explore a Database Projects’ Inner Workings using SSDT Schema Compare Dan Romano 1y
  • What is XML : Why We Can Use It Best explanation With Example on 2024 Nexotips Infotech 4mo
  • All About LINQ Queries in C#: A Comprehensive Guide Asharib Kamal 1mo
  • GUID vs ULID in .NET C# Ashraf Faheem 2mo
  • Laravel Eloquent One-To-One Relationship - Ultimate Guide 2023 Mahmoud Adel 1y
  • C# Keywords Tutorial Part 10: by Amr Saafan 1y
  • How to Make Your LINQ Extensions Reusable for Other Developers Peter Smulovics 1y
  • Understanding require function (Node.js) Matias Daniel Torre 11mo
  • Why LINQ beats SQL RAUNAK DEEP SRIVASTAVA 8y

Explore topics

  • Sales
  • Marketing
  • IT Services
  • Business Administration
  • HR Management
  • Engineering
  • Soft Skills
  • See All
C# Keywords Tutorial Part 99: where (2024)
Top Articles
The best free VPNs of 2024: Expert tested
The best beginners' guide to buying and selling forex
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6562

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.