Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion Linq/Linq.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
using System;
using System.Linq;

namespace Linq
{
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;
}
}
}
26 changes: 26 additions & 0 deletions LinqProject/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
15 changes: 15 additions & 0 deletions LinqProject/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/LinqProject.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
8 changes: 8 additions & 0 deletions LinqProject/LinqProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

</Project>
46 changes: 46 additions & 0 deletions LinqProject/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace LinqProject
{
public class Program
{
public static void Main()
{
List<Student> students = new List<Student>();

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