-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathLinq.cs
More file actions
48 lines (40 loc) · 1.45 KB
/
Linq.cs
File metadata and controls
48 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
namespace Linq
{
class Program
{
static void Main()
{
List<Student> students = new List<Student>();
students.Add(new Student("Chris", "123-456-7891", "123 Delany", -2990));
students.Add(new Student("Terry", "198-765-4321", "321 ynaled", -2500));
students.Add(new Student("Victoria", "512-827-8498", "701 Brazos St", 0));
students.Add(new Student("Luke", "555-555-5555", "451 Brody Ln", -500));
students.Add(new Student("Jessica", "210-895-6658", "578 Blackhill blvd",-3600));
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;
}
}
}