diff --git a/Linq/Linq.cs b/Linq/Linq.cs index 6cabb44e..e40c456b 100644 --- a/Linq/Linq.cs +++ b/Linq/Linq.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; namespace Linq { @@ -6,7 +7,25 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + var source = new int[] { 1, 2, 3 }; + + var results = + from i in source + where isEven(i) + select Square(i); + + int total = source.Where(isEven).Select(Square).Sum(); + // var total = results.Sum(); + } + + public static bool isEven(int i) + { + return i % 2 == 0; + } + + public static int Square(int value) + { + return value * value; } } } diff --git a/LinqProject/.vscode/launch.json b/LinqProject/.vscode/launch.json new file mode 100644 index 00000000..c5f9a444 --- /dev/null +++ b/LinqProject/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.2/LinqProject.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "integratedTerminal", + "stopAtEntry": false, + "internalConsoleOptions": "openOnSessionStart" + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/LinqProject/.vscode/tasks.json b/LinqProject/.vscode/tasks.json new file mode 100644 index 00000000..e353b470 --- /dev/null +++ b/LinqProject/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/LinqProject.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/LinqProject/LinqProject.csproj b/LinqProject/LinqProject.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/LinqProject/LinqProject.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/LinqProject/Program.cs b/LinqProject/Program.cs new file mode 100644 index 00000000..c39ea007 --- /dev/null +++ b/LinqProject/Program.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace LinqProject +{ + public class Program + { + public static void Main() + { + List students = new List(); + + students.Add(new Student("Chris", "123-456-7891", "123 Delany", -2990)); + students.Add(new Student("Kevin", "512-222-2222", "435 Carolyn", -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)); + + //your code here + + List results = students.FindAll(x => x.Balance < 0); + + foreach (var item in results) + { + Console.WriteLine(item.Name + " still owes " + item.Balance * -1 + " they can be reached at " + item.Phone + "."); + } + } + + } + + 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; + } + } +} +