Skip to content

Commit

Permalink
Aggiunti gli esercizi su LINQ
Browse files Browse the repository at this point in the history
  • Loading branch information
Moreno Gentili committed Apr 9, 2019
1 parent 4b02eb9 commit 2cee6d2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/linq/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Script Debug",
"type": "coreclr",
"request": "launch",
"program": "dotnet",
"args": [
"exec",
"C:/Users/brigh/.dotnet/tools/.store/dotnet-script/0.28.0/dotnet-script/0.28.0/tools/netcoreapp2.1/any/dotnet-script.dll",
"${file}"
],
"cwd": "${workspaceRoot}",
"stopAtEntry": true
}
]
}
35 changes: 35 additions & 0 deletions scripts/linq/main.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//Per fare il debug di questi esempi, devi prima installare il global tool dotnet-script con questo comando:
//dotnet tool install -g dotnet-script
//Trovi altre istruzioni nel file /scripts/readme.md
class Apple {
public string Color { get; set; }
public int Weight { get; set; } //In grammi
}

List<Apple> apples = new List<Apple> {
new Apple { Color = "Red", Weight = 180 },
new Apple { Color = "Green", Weight = 195 },
new Apple { Color = "Red", Weight = 190 },
new Apple { Color = "Green", Weight = 185 },
};

//ESEMPIO #1: Ottengo i pesi delle mele rosse
IEnumerable<int> weightsOfRedApples = apples
.Where(apple => apple.Color == "Red")
.Select(apple => apple.Weight);

//ESEMPIO #2: Calcolo la media dei pesi ottenuti
double average = weightsOfRedApples.Average();
Console.WriteLine();

//ESERCIZIO #1: Qual è il peso minimo delle 4 mele?
//int minimumWeight = apples...;

//ESERCIZIO #2: Di che colore è la mela che pesa 190 grammi?
//string color = apples...;

//ESERCIZIO #3: Quante sono le mele rosse?
//int redAppleCount = apples...;

//ESERCIZIO #4: Qual è il peso totale delle mele verdi?
//int totalWeight = apples...;
6 changes: 6 additions & 0 deletions scripts/linq/omnisharp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"script": {
"enableScriptNuGetReferences": true,
"defaultTargetFramework": "netcoreapp2.1"
}
}

0 comments on commit 2cee6d2

Please sign in to comment.