Compare commits
3 Commits
master
...
3_linq_que
Author | SHA1 | Date |
---|---|---|
jason.zhu | af986b0d09 | |
jason.zhu | 46766de185 | |
jason.zhu | 512d8304e7 |
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||||
|
// Use hover for the description of the existing attributes
|
||||||
|
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||||
|
"name": ".NET Core Launch (console)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
// If you have changed target frameworks, make sure to update the program path.
|
||||||
|
"program": "${workspaceFolder}/Introduction/bin/Debug/netcoreapp3.1/Introduction.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/Introduction",
|
||||||
|
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||||
|
"console": "internalConsole",
|
||||||
|
"stopAtEntry": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": ".NET Core Attach",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "attach",
|
||||||
|
"processId": "${command:pickProcess}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/Introduction/Introduction.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "publish",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/Introduction/Introduction.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"${workspaceFolder}/Introduction/Introduction.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Queries
|
||||||
|
{
|
||||||
|
public class Movie
|
||||||
|
{
|
||||||
|
public string Title { get; set; }
|
||||||
|
public float Rating { get; set; }
|
||||||
|
private int _year;
|
||||||
|
public int Year {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Returning {_year} for {Title}");
|
||||||
|
return _year;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_year = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Dynamic;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Queries
|
||||||
|
{
|
||||||
|
public static class MyLinq
|
||||||
|
{
|
||||||
|
public static IEnumerable<T> Filter<T>(this IEnumerable<T> source,
|
||||||
|
Func<T, bool> predicate)
|
||||||
|
{
|
||||||
|
// define a customized filter extension for LINQ
|
||||||
|
// demonstrate how to create a customized LINQ filter
|
||||||
|
var result = new List<T>();
|
||||||
|
|
||||||
|
foreach (var item in source)
|
||||||
|
{
|
||||||
|
if (predicate(item))
|
||||||
|
{
|
||||||
|
yield return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Queries
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var movies = new List<Movie>
|
||||||
|
{
|
||||||
|
new Movie {Title = "The Dark Knight", Rating = 8.9f, Year = 2008},
|
||||||
|
new Movie {Title = "The King's Speech", Rating = 8.0f, Year = 2010},
|
||||||
|
new Movie {Title = "Casablanca", Rating = 8.5f, Year = 1942},
|
||||||
|
new Movie {Title = "Star Wars V", Rating = 8.5f, Year = 1980}
|
||||||
|
};
|
||||||
|
|
||||||
|
// filter operator from LINQ
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Filter operator from LINQ");
|
||||||
|
var query = movies.Where(m => m.Year > 2000);
|
||||||
|
foreach (var movie in query)
|
||||||
|
{
|
||||||
|
Console.WriteLine(movie.Title);
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter operator using customized Filter extension
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("Customerized Filter operator");
|
||||||
|
var query2 = movies.Filter(m => m.Year > 2000);
|
||||||
|
foreach (var movie in query2)
|
||||||
|
{
|
||||||
|
Console.WriteLine(movie.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Introduction", "Introductio
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features", "Features\Features.csproj", "{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Features", "Features\Features.csproj", "{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Queries", "Queries\Queries.csproj", "{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "yield_test", "yield_test\yield_test.csproj", "{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -44,5 +48,29 @@ Global
|
||||||
{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}.Release|x64.Build.0 = Release|Any CPU
|
{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}.Release|x86.ActiveCfg = Release|Any CPU
|
{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}.Release|x86.Build.0 = Release|Any CPU
|
{94C9EE4C-0609-464B-9BFF-BA3EED2A7263}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{FB21B6B5-70C3-444E-A1D1-2CCD3F575DD9}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{790E4D64-D90A-4289-9F5D-35B6A2BDBE5B}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace yield_test
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
foreach (var number in GetNumbers())
|
||||||
|
{
|
||||||
|
Console.WriteLine(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable GetNumbers()
|
||||||
|
{
|
||||||
|
yield return 1;
|
||||||
|
yield return 2;
|
||||||
|
yield return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in New Issue