forked from benperk/BeginningCSharp7
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 22: Introduction and Applying LINQ
- Loading branch information
1 parent
2dd9768
commit f43abb8
Showing
57 changed files
with
1,974 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Chapter22/BeginningCSharp7_22_10_GroupQuery/BeginningCSharp7_22_10_GroupQuery.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26730.16 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeginningCSharp7_22_10_GroupQuery", "BeginningCSharp7_22_10_GroupQuery\BeginningCSharp7_22_10_GroupQuery.csproj", "{67AEA3AE-9761-466C-B916-A0CECCBF652A}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{67AEA3AE-9761-466C-B916-A0CECCBF652A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{67AEA3AE-9761-466C-B916-A0CECCBF652A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{67AEA3AE-9761-466C-B916-A0CECCBF652A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{67AEA3AE-9761-466C-B916-A0CECCBF652A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {3A421933-9092-494F-B6D1-AA87E3B1B5D3} | ||
EndGlobalSection | ||
EndGlobal |
6 changes: 6 additions & 0 deletions
6
Chapter22/BeginningCSharp7_22_10_GroupQuery/BeginningCSharp7_22_10_GroupQuery/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/> | ||
</startup> | ||
</configuration> |
53 changes: 53 additions & 0 deletions
53
..._10_GroupQuery/BeginningCSharp7_22_10_GroupQuery/BeginningCSharp7_22_10_GroupQuery.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{67AEA3AE-9761-466C-B916-A0CECCBF652A}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>BeginningCSharp7_22_10_GroupQuery</RootNamespace> | ||
<AssemblyName>BeginningCSharp7_22_10_GroupQuery</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
68 changes: 68 additions & 0 deletions
68
Chapter22/BeginningCSharp7_22_10_GroupQuery/BeginningCSharp7_22_10_GroupQuery/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using static System.Console; | ||
|
||
namespace BeginningCSharp7_22_10_GroupQuery | ||
{ | ||
class Customer | ||
{ | ||
public string ID { get; set; } | ||
public string City { get; set; } | ||
public string Country { get; set; } | ||
public string Region { get; set; } | ||
public decimal Sales { get; set; } | ||
|
||
} | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
List<Customer> customers = new List<Customer> { | ||
new Customer { ID="A", City="New York", Country="USA", Region="North America", Sales=9999}, | ||
new Customer { ID="B", City="Mumbai", Country="India", Region="Asia", Sales=8888}, | ||
new Customer { ID="C", City="Karachi", Country="Pakistan", Region="Asia", Sales=7777}, | ||
new Customer { ID="D", City="Delhi", Country="India", Region="Asia", Sales=6666}, | ||
new Customer { ID="E", City="São Paulo", Country="Brazil", Region="South America", Sales=5555 }, | ||
new Customer { ID="F", City="Moscow", Country="Russia", Region="Europe", Sales=4444 }, | ||
new Customer { ID="G", City="Seoul", Country="Korea", Region="Asia", Sales=3333 }, | ||
new Customer { ID="H", City="Istanbul", Country="Turkey", Region="Asia", Sales=2222 }, | ||
new Customer { ID="I", City="Shanghai", Country="China", Region="Asia", Sales=1111 }, | ||
new Customer { ID="J", City="Lagos", Country="Nigeria", Region="Africa", Sales=1000 }, | ||
new Customer { ID="K", City="Mexico City", Country="Mexico", Region="North America", Sales=2000 }, | ||
new Customer { ID="L", City="Jakarta", Country="Indonesia", Region="Asia", Sales=3000 }, | ||
new Customer { ID="M", City="Tokyo", Country="Japan", Region="Asia", Sales=4000 }, | ||
new Customer { ID="N", City="Los Angeles", Country="USA", Region="North America", Sales=5000 }, | ||
new Customer { ID="O", City="Cairo", Country="Egypt", Region="Africa", Sales=6000 }, | ||
new Customer { ID="P", City="Tehran", Country="Iran", Region="Asia", Sales=7000 }, | ||
new Customer { ID="Q", City="London", Country="UK", Region="Europe", Sales=8000 }, | ||
new Customer { ID="R", City="Beijing", Country="China", Region="Asia", Sales=9000 }, | ||
new Customer { ID="S", City="Bogotá", Country="Colombia", Region="South America", Sales=1001 }, | ||
new Customer { ID="T", City="Lima", Country="Peru", Region="South America", Sales=2002 } | ||
}; | ||
|
||
var queryResults = | ||
from c in customers | ||
group c by c.Region into cg | ||
select new { TotalSales = cg.Sum(c => c.Sales), Region = cg.Key } | ||
; | ||
|
||
var orderedResults = | ||
from cg in queryResults | ||
orderby cg.TotalSales descending | ||
select cg | ||
; | ||
|
||
|
||
WriteLine("Total\t: By\nSales\t: Region\n-----\t ------"); | ||
foreach (var item in orderedResults) | ||
{ | ||
WriteLine($"{item.TotalSales}\t: {item.Region}"); | ||
} | ||
Write("Program finished, press Enter/Return to continue:"); | ||
ReadLine(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ningCSharp7_22_10_GroupQuery/BeginningCSharp7_22_10_GroupQuery/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("BeginningCSharp7_22_10_GroupQuery")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("BeginningCSharp7_22_10_GroupQuery")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("67aea3ae-9761-466c-b916-a0ceccbf652a")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
25 changes: 25 additions & 0 deletions
25
Chapter22/BeginningCSharp7_22_11_JoinQuery/BeginningCSharp7_22_11_JoinQuery.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26730.16 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeginningCSharp7_22_11_JoinQuery", "BeginningCSharp7_22_11_JoinQuery\BeginningCSharp7_22_11_JoinQuery.csproj", "{AF7D3D45-76A9-4440-A667-D665A2DF9F20}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AF7D3D45-76A9-4440-A667-D665A2DF9F20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AF7D3D45-76A9-4440-A667-D665A2DF9F20}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AF7D3D45-76A9-4440-A667-D665A2DF9F20}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AF7D3D45-76A9-4440-A667-D665A2DF9F20}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {464082E1-9FEC-47A6-8F88-D2893AC41BFF} | ||
EndGlobalSection | ||
EndGlobal |
6 changes: 6 additions & 0 deletions
6
Chapter22/BeginningCSharp7_22_11_JoinQuery/BeginningCSharp7_22_11_JoinQuery/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/> | ||
</startup> | ||
</configuration> |
Oops, something went wrong.