Book Image

Learn C# in 7 days

By : Gaurav Aroraa
1 (1)
Book Image

Learn C# in 7 days

1 (1)
By: Gaurav Aroraa

Overview of this book

This book takes a unique approach to teach C# to absolute beginners. You’ll learn the basics of the language in seven days. It takes a practical approach to explain the important concepts that build the foundation of the C# programming language. The book begins by teaching you the basic fundamentals using real-world practical examples and gets you acquainted with C# programming. We cover some important features and nuances of the language in a hands-on way, helping you grasp the concepts in a fluid manner. Later, you’ll explore the concepts of Object-Oriented Programming (OOP) through a real-world example. Then we dive into advanced-level concepts such as generics and collections, and you’ll get acquainted with objects and LINQ. Towards the end, you’ll build an application that covers all the concepts explained in the book. By the end of this book, you will have next-level skills and a good knowledge of the fundamentals of C#.
Table of Contents (15 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Getting started with LINQ


LINQ is nothing but an acronym of Language Integrated Query that is part of programming language. LINQ provides an easy way to write or query data with a specified syntax like we would use the where clause when trying to query data for some specific criteria. So, we can say that LINQ is a syntax that is used to query data.

In this section, we will see a simple example to query data. We have Person list and the following code snippet provides us a various way to query data:

private static void TestLINQ() 
{ 
    var person = from p in Person.GetPersonList() 
        where p.Id == 1 
        select p; 
    foreach (var per in person) 
    { 
        WriteLine($"Person Id:{per.Id}"); 
        WriteLine($"Name:{per.FirstName} {per.LastName}"); 
        WriteLine($"Age:{per.Age}"); 
    } 
     
} 

In the preceding code snippet, we are querying List of persons for personId =1. The LINQ query returns a result of IEnumerable<Person> type which can be easily accessed...