This commit is contained in:
orosmatthew 2024-02-26 09:32:12 -05:00
parent 313504f690
commit 64259e5208
35 changed files with 43 additions and 322 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/LinqActivity/bin
/LinqActivity/obj
/.vs

Binary file not shown.

Binary file not shown.

View File

@ -1,30 +1,30 @@
using System.Collections.Generic; using System.Text;
namespace LinqActivity namespace LinqActivity
{ {
class Program internal class Program
{ {
static void Main(string[] args) private static void Main()
{ {
Console.WriteLine("LINQ Activity - 2/23/2024"); Console.WriteLine("LINQ Activity - 2/23/2024");
Console.WriteLine("Name: INSERT NAME HERE"); Console.WriteLine("Name: Matthew Oros");
List<Patient> patients = new List<Patient> var patients = new List<Patient>
{ {
new Patient("John", 25, 5, 8, 180, new DateTime(2022,2, 18)), new("John", 25, 5, 8, 180, new DateTime(2022,2, 18)),
new Patient("Jane", 30, 5, 5, 150, new DateTime(2023,1, 10)), new("Jane", 30, 5, 5, 150, new DateTime(2023,1, 10)),
new Patient("Joe", 28, 6, 0, 200, new DateTime(2020, 7, 23)), new("Joe", 28, 6, 0, 200, new DateTime(2020, 7, 23)),
new Patient("Jill", 35, 5, 7, 160, new DateTime(2021, 3, 20)), new("Jill", 35, 5, 7, 160, new DateTime(2021, 3, 20)),
new Patient("Jack", 40, 5, 10, 190, new DateTime(2022, 8, 1)) new("Jack", 40, 5, 10, 190, new DateTime(2022, 8, 1))
}; };
List<Patient> transferPatients = new List<Patient> var transferPatients = new List<Patient>
{ {
new Patient("Bobby", 35, 5, 8, 180, new DateTime(2022,2, 18)), new("Bobby", 35, 5, 8, 180, new DateTime(2022,2, 18)),
new Patient("Jamison", 33, 5, 5, 150, new DateTime(2023,1, 10)), new("Jamison", 33, 5, 5, 150, new DateTime(2023,1, 10)),
new Patient("Elijah", 48, 6, 0, 200, new DateTime(2020, 7, 23)), new("Elijah", 48, 6, 0, 200, new DateTime(2020, 7, 23)),
new Patient("Bill", 15, 5, 7, 160, new DateTime(2021, 3, 20)), new("Bill", 15, 5, 7, 160, new DateTime(2021, 3, 20)),
new Patient("Jack", 40, 5, 10, 190, new DateTime(2022, 8, 1)), new("Jack", 40, 5, 10, 190, new DateTime(2022, 8, 1)),
new Patient("Jack", 40, 5, 10, 190, new DateTime(2022, 8, 1)) new("Jack", 40, 5, 10, 190, new DateTime(2022, 8, 1))
}; };
@ -65,7 +65,7 @@ namespace LinqActivity
Console.WriteLine("\n6.) Distinct Transfer Patients"); Console.WriteLine("\n6.) Distinct Transfer Patients");
var transferPatientNames = transferPatients.Select(p => p.Name).ToList(); var transferPatientNames = transferPatients.Select(p => p.Name).ToList();
var distinctTransferPatientsNames = DistinctTransferPatients(transferPatientNames); var distinctTransferPatientsNames = DistinctTransferPatients(transferPatientNames);
if(distinctTransferPatientsNames!=null) if (distinctTransferPatientsNames != null)
Console.WriteLine(string.Join(", ", distinctTransferPatientsNames)); Console.WriteLine(string.Join(", ", distinctTransferPatientsNames));
//7.) Write a LINQ Query that checks if the list of patients contains ANY patients with the name "Joe" //7.) Write a LINQ Query that checks if the list of patients contains ANY patients with the name "Joe"
@ -81,7 +81,7 @@ namespace LinqActivity
}//END Main }//END Main
public static void DisplayPatients(List<Patient> patients) public static void DisplayPatients(List<Patient>? patients)
{ {
if (patients == null) if (patients == null)
{ {
@ -90,64 +90,59 @@ namespace LinqActivity
} }
foreach (var patient in patients) foreach (var patient in patients)
{ {
Console.WriteLine($"Name: {patient.Name}, Age: {patient.Age}, Height: {patient.HeightFeet}'{patient.HeightInches}\", Weight: {patient.Weight} lbs, DateCreated: {patient.DateCreated.ToString("MMddyyyy")}."); Console.WriteLine($"Name: {patient.Name}, Age: {patient.Age}, Height: {patient.HeightFeet}'{patient.HeightInches}\", Weight: {patient.Weight} lbs, DateCreated: {patient.DateCreated:MMddyyyy}.");
} }
} }
//1.) Write a LINQ query that returns all patients over the age of 30 in the "Patients" list //1.) Write a LINQ query that returns all patients over the age of 30 in the "Patients" list
public static List<Patient> AllPatientsOver30(List<Patient> patients) public static List<Patient>? AllPatientsOver30(List<Patient>? patients)
{ {
return patients?.Where(p => p.Age > 30).ToList();
return null;
} }
//2.) Write a LINQ query that takes the patients in the Patients list, and returns a string of their names separated by a comma //2.) Write a LINQ query that takes the patients in the Patients list, and returns a string of their names separated by a comma
public static string AllPatientNames(List<Patient> patients) public static string AllPatientNames(List<Patient>? patients)
{ {
var sb = new StringBuilder();
return null; patients?.ForEach(p => sb.Append($"{p.Name}, "));
return sb.ToString();
} }
//3.) Write a LINQ query that returns the average weight of all patients in the Patients list //3.) Write a LINQ query that returns the average weight of all patients in the Patients list
public static decimal AverageWeightOfAllPatients(List<Patient> patients) public static decimal? AverageWeightOfAllPatients(List<Patient>? patients)
{ {
return patients?.Average(p => p.Weight);
return 0;
} }
//4.) Write a LINQ query that orders the list of patients in the Patients list by DateCreated and returns the most recent //4.) Write a LINQ query that orders the list of patients in the Patients list by DateCreated and returns the most recent
public static Patient MostRecentPatientCreated(List<Patient> patients) public static Patient? MostRecentPatientCreated(List<Patient>? patients)
{ {
return patients?.OrderByDescending(p => p.DateCreated).First();
return null;
} }
//5.) Write a LINQ Query that concatenates the two lists of patients together //5.) Write a LINQ Query that concatenates the two lists of patients together
public static List<Patient> ConcatPatientLists(List<Patient> patients, List<Patient> transferPatients) public static List<Patient>? ConcatPatientLists(List<Patient>? patients, List<Patient>? transferPatients)
{ {
if (transferPatients != null) patients?.AddRange(transferPatients);
return null; return transferPatients;
} }
//6.)Given the last of transferParentNames below, write a LINQ Query within DistinctTransferPatients that returns a list of distinct names //6.)Given the last of transferParentNames below, write a LINQ Query within DistinctTransferPatients that returns a list of distinct names
public static List<String> DistinctTransferPatients(List<String> transferPatientNames) public static List<string>? DistinctTransferPatients(List<string>? transferPatientNames)
{ {
return transferPatientNames?.Distinct().ToList();
return null;
} }
//7.) Write a LINQ Query that checks if the list of patients contains ANY patients with the name "Joe" //7.) Write a LINQ Query that checks if the list of patients contains ANY patients with the name "Joe"
public static bool ContainsJoe(List<Patient> patients) public static bool? ContainsJoe(List<Patient>? patients)
{ {
return patients?.Select(p => p.Name).Contains("Joe");
return false;
} }
//8.) Write a LINQ Query that TAKEs the first 3 patients in the patient list //8.) Write a LINQ Query that TAKEs the first 3 patients in the patient list
public static List<Patient> First3Patients(List<Patient> patients) public static List<Patient>? First3Patients(List<Patient>? patients)
{ {
return patients?.Take(3).ToList();
return null;
} }
} }
@ -166,7 +161,7 @@ namespace LinqActivity
public override string ToString() public override string ToString()
{ {
return $"Name: {Name}, Age: {Age}, Height: {HeightFeet}'{HeightInches}\", Weight: {Weight} lbs, DateCreated: {DateCreated.ToString("MMddyyyy")}."; return $"Name: {Name}, Age: {Age}, Height: {HeightFeet}'{HeightInches}\", Weight: {Weight} lbs, DateCreated: {DateCreated:MMddyyyy}.";
} }

View File

@ -1,23 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"LinqActivity/1.0.0": {
"runtime": {
"LinqActivity.dll": {}
}
}
}
},
"libraries": {
"LinqActivity/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

View File

@ -1,9 +0,0 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

View File

@ -1,4 +0,0 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]

View File

@ -1,23 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("LinqActivity")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("LinqActivity")]
[assembly: System.Reflection.AssemblyTitleAttribute("LinqActivity")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -1 +0,0 @@
438b036c34a1df04bbcf7f238d6dc799e495b870

View File

@ -1,11 +0,0 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = LinqActivity
build_property.ProjectDir = C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\

View File

@ -1,8 +0,0 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@ -1 +0,0 @@
218b79da7a08bc07bb997a020130a11d082c22df

View File

@ -1,28 +0,0 @@
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\bin\Debug\net6.0\LinqActivity.exe
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\bin\Debug\net6.0\LinqActivity.deps.json
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\bin\Debug\net6.0\LinqActivity.runtimeconfig.json
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\bin\Debug\net6.0\LinqActivity.dll
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\bin\Debug\net6.0\LinqActivity.pdb
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.GeneratedMSBuildEditorConfig.editorconfig
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.AssemblyInfoInputs.cache
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.AssemblyInfo.cs
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.csproj.CoreCompileInputs.cache
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.dll
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\refint\LinqActivity.dll
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.pdb
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\LinqActivity.genruntimeconfig.cache
C:\Coding Projects - not in repo\LinqActivity\LinqActivity\obj\Debug\net6.0\ref\LinqActivity.dll
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\bin\Debug\net6.0\LinqActivity.exe
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\bin\Debug\net6.0\LinqActivity.deps.json
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\bin\Debug\net6.0\LinqActivity.runtimeconfig.json
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\bin\Debug\net6.0\LinqActivity.dll
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\bin\Debug\net6.0\LinqActivity.pdb
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.GeneratedMSBuildEditorConfig.editorconfig
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.AssemblyInfoInputs.cache
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.AssemblyInfo.cs
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.csproj.CoreCompileInputs.cache
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.dll
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\refint\LinqActivity.dll
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.pdb
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\LinqActivity.genruntimeconfig.cache
C:\GitRepos\MG-TechTalk-LINQ\LinqActivity\obj\Debug\net6.0\ref\LinqActivity.dll

View File

@ -1 +0,0 @@
ad3b8f348f7564c7cd2752667aabc937396fbef4

View File

@ -1,68 +0,0 @@
{
"format": 1,
"restore": {
"C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj": {}
},
"projects": {
"C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj",
"projectName": "LinqActivity",
"projectPath": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj",
"packagesPath": "C:\\Users\\laten\\.nuget\\packages\\",
"outputPath": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\laten\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.403\\RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\laten\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.7.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\laten\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -1,74 +0,0 @@
{
"version": 3,
"targets": {
"net6.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net6.0": []
},
"packageFolders": {
"C:\\Users\\laten\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj",
"projectName": "LinqActivity",
"projectPath": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj",
"packagesPath": "C:\\Users\\laten\\.nuget\\packages\\",
"outputPath": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\laten\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\dotnet\\library-packs": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.403\\RuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -1,8 +0,0 @@
{
"version": 2,
"dgSpecHash": "pWNG4+B2Uri+Cq6CEGGdUPIaSa97+gvGEG80SRHApu9cM29gpQX7kmLnopcTYO1achJvSv82L6yf30FFtsTowQ==",
"success": true,
"projectFilePath": "C:\\GitRepos\\MG-TechTalk-LINQ\\LinqActivity\\LinqActivity.csproj",
"expectedPackageFiles": [],
"logs": []
}