From bafe36a87b911332906c99f0ff78536ed787003d Mon Sep 17 00:00:00 2001 From: Michael Rich Date: Wed, 28 Nov 2018 20:01:56 -0600 Subject: [PATCH] finished Linq program --- Linq/Linq.cs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Linq/Linq.cs b/Linq/Linq.cs index 6cabb44e..f9f544fe 100644 --- a/Linq/Linq.cs +++ b/Linq/Linq.cs @@ -1,12 +1,44 @@ using System; +using System.Collections.Generic; +using System.Linq; namespace Linq { - class Program + public class Program { - static void Main(string[] args) + public static void Main() { - Console.WriteLine("Hello World!"); + List students = new List(); + + students.Add(new Student("Chris", "123-456-7891", "123 Delany", -2990)); + students.Add(new Student("Jill", "555-555-5555", "321 Racoon Dr.", -2500)); + students.Add(new Student("Jennifer", "210-867-5309", "5789 Stacy St.", 0)); + students.Add(new Student("Ronald", "1 (800) 244-6227", "110 North Carpenter Street", -500)); + + IEnumerable negativeBalance = from currentStudent in students + where currentStudent.Balance < 0 + select currentStudent; + + Console.WriteLine("all the students with a negative balance"); + foreach(Student currentStudent in negativeBalance){ + Console.WriteLine(currentStudent.Name); + } + } + } + + public class Student + { + public string Name {get; set;} + public string Phone {get; set;} + public string Address {get; set;} + public int Balance {get; set;} + + public Student (string name, string phone, string address, int balance) + { + Name = name; + Phone = phone; + Address = address; + Balance = balance; } } }