Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions Linq/Linq.cs
Original file line number Diff line number Diff line change
@@ -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<Student> students = new List<Student>();

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<Student> 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;
}
}
}