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
Restore purchases in mobile app | Adapty
sacrilegus - Wiktionary, the free dictionary
Is Paige Vanzant Related To Ronnie Van Zant
Botw Royal Guard
The 10 Best Restaurants In Freiburg Germany
Nc Maxpreps
Bellinghamcraigslist
Cumberland Maryland Craigslist
Athletic Squad With Poles Crossword
Wfin Local News
What Was D-Day Weegy
No Credit Check Apartments In West Palm Beach Fl
Robot or human?
Walmart Windshield Wiper Blades
Haunted Mansion Showtimes Near Millstone 14
111 Cubic Inch To Cc
Ess.compass Associate Login
Hanger Clinic/Billpay
Mikayla Campinos Laek: The Rising Star Of Social Media
Jang Urdu Today
Metro Pcs.near Me
Webcentral Cuny
Vegito Clothes Xenoverse 2
Www.craigslist.com Savannah Ga
Coomeet Premium Mod Apk For Pc
Vernon Dursley To Harry Potter Nyt Crossword
Southland Goldendoodles
Aliciabibs
Weldmotor Vehicle.com
Haunted Mansion Showtimes Near Epic Theatres Of West Volusia
Southwest Flight 238
Why Are Fuel Leaks A Problem Aceable
Pioneer Library Overdrive
Cylinder Head Bolt Torque Values
Uky Linkblue Login
Urban Blight Crossword Clue
Reli Stocktwits
2012 Street Glide Blue Book Value
To Give A Guarantee Promise Figgerits
Umiami Sorority Rankings
Ticketmaster Lion King Chicago
Hingham Police Scanner Wicked Local
Mckinley rugzak - Mode accessoires kopen? Ruime keuze
The Transformation Of Vanessa Ray From Childhood To Blue Bloods - Looper
Labyrinth enchantment | PoE Wiki
Gun Mayhem Watchdocumentaries
Alston – Travel guide at Wikivoyage
The Average Amount of Calories in a Poke Bowl | Grubby's Poke
Craiglist.nj
Lsreg Att
Jasgotgass2
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.