Update code
This commit is contained in:
parent
d02a9fda6c
commit
1e999368ac
10 changed files with 85 additions and 186 deletions
|
@ -1,29 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace StackVsHeap1
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var dateOfBirth = new DateTime(1987, 05, 01);
|
||||
var age = CalculateAge(dateOfBirth);
|
||||
|
||||
Console.WriteLine(age);
|
||||
}
|
||||
|
||||
private static int CalculateAge(DateTime dateOfBirth)
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - dateOfBirth.Year;
|
||||
|
||||
if (dateOfBirth.Date > today.AddYears(-age))
|
||||
age--;
|
||||
|
||||
return age;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>StackVsHeap1</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,34 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace StackVsHeap2
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
const int MAX_AGE = 99;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var dateOfBirth = new DateTime(1900, 05, 01);
|
||||
var age = CalculateAge(dateOfBirth);
|
||||
|
||||
if (age >= MAX_AGE)
|
||||
Console.WriteLine($"Are you sure you are {age}?");
|
||||
else
|
||||
Console.WriteLine(age);
|
||||
}
|
||||
|
||||
private static int CalculateAge(DateTime dateOfBirth)
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - dateOfBirth.Year;
|
||||
|
||||
if (dateOfBirth.Date > today.AddYears(-age))
|
||||
age--;
|
||||
|
||||
return age;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>StackVsHeap2</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,34 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace StackVsHeap3
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var maxAge = 99;
|
||||
var dateOfBirth = new DateTime(1900, 05, 01);
|
||||
var calculateAge = () =>
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - dateOfBirth.Year;
|
||||
|
||||
if (dateOfBirth.Date > today.AddYears(-age))
|
||||
age--;
|
||||
|
||||
return age;
|
||||
};
|
||||
|
||||
var age = calculateAge();
|
||||
|
||||
if (age >= maxAge)
|
||||
Console.WriteLine($"Are you sure you are {age}?");
|
||||
else
|
||||
Console.WriteLine(age);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>StackVsHeap3</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,44 +0,0 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StackVsHeap4
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var dateOfBirth = new DateTime(1900, 05, 01);
|
||||
var ageTask = CalculateAge(dateOfBirth);
|
||||
var otherTask = DoSomethingElse();
|
||||
|
||||
await Task.WhenAll(ageTask, otherTask);
|
||||
|
||||
var age = ageTask.Result;
|
||||
|
||||
Console.WriteLine(age);
|
||||
}
|
||||
|
||||
private static async Task<int> CalculateAge(DateTime dateOfBirth)
|
||||
{
|
||||
var today = DateTime.Today;
|
||||
var age = today.Year - dateOfBirth.Year;
|
||||
|
||||
await Task.Delay(1000); // Pretending to do work
|
||||
|
||||
if (dateOfBirth.Date > today.AddYears(-age))
|
||||
age--;
|
||||
|
||||
return age;
|
||||
}
|
||||
|
||||
|
||||
private static async Task DoSomethingElse()
|
||||
{
|
||||
Console.WriteLine("Doing some other work");
|
||||
await Task.Delay(2000); // Pretending to do work
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>StackVsHeap4</RootNamespace>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -1,13 +1,16 @@
|
|||
# Code featured in my YouTube videos
|
||||
This repository contains all the code from the following YouTube videos. The code from the other videos have their own separate repository.
|
||||
|
||||
> [!NOTE]
|
||||
> [This repository](https://code.alexhyett.com/alexhyett/youtube-code) is also mirrored on [Codeberg.org](https://codeberg.org/alexhyett/youtube-code) if you want to raise an issue.
|
||||
|
||||
## Index of all the code by YouTube video and date
|
||||
I will add new code as soon as I am done editing the videos. So, you might find the latest on this video hasn't been released yet.
|
||||
|
||||
| Date Published | Video | Link |
|
||||
| -------------- | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
||||
| 2022-12-09 | [Big O Notation](https://youtu.be/aIG48ldbpRI) | [code](2022-12-09-Big-O-Notation) |
|
||||
| 2022-11-25 | [Stack vs Heap](https://youtu.be/5OJRqkYbK-4) | [code](2022-11-25-Stack-Vs-Heap) |
|
||||
| 2022-11-25 | [Stack vs Heap](https://youtu.be/5OJRqkYbK-4) | [code](/alexhyett/stack-vs-heap) |
|
||||
| 2022-11-11 | [Automate Your Life With Python (File Management Step By Step Example)](https://youtu.be/1dgnl7oCVTY) | [code](2022-11-11-Automate-Your-Life-With-Python/move-photos.py) |
|
||||
| 2022-10-21 | [Bitwise Operators and WHY we use them](https://youtu.be/igIjGxF2J-w) | [code](2022-10-21-Bitwise-Operators-and-WHY-we-use-them) |
|
||||
| 2022-10-10 | [6 Coding Concepts You MUST Know For Beginners](https://youtu.be/pKFcVs2HibA) | [code](2022-10-10-6-Coding-Concepts-You-MUST-Know-For-Beginners) |
|
||||
|
|
81
youtube-code.sln
Normal file
81
youtube-code.sln
Normal file
|
@ -0,0 +1,81 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.002.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2022-11-25-Stack-Vs-Heap", "2022-11-25-Stack-Vs-Heap", "{D9274304-4A5B-457C-9F94-0D43FCB34306}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackVsHeap2", "2022-11-25-Stack-Vs-Heap\Example2\StackVsHeap2.csproj", "{84D0E2A6-F29D-4E7A-A9A7-7B3B189858B4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackVsHeap4", "2022-11-25-Stack-Vs-Heap\Example4\StackVsHeap4.csproj", "{88871D7B-C1E5-40A9-99D5-C4728F4F9F34}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackVsHeap3", "2022-11-25-Stack-Vs-Heap\Example3\StackVsHeap3.csproj", "{738D63F4-EC3C-4228-8CDD-49F225D63F50}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackVsHeap1", "2022-11-25-Stack-Vs-Heap\Example1\StackVsHeap1.csproj", "{687246E4-702E-40D2-A00F-A6D8933EFE76}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2022-12-09-Big-O-Notation", "2022-12-09-Big-O-Notation", "{44A151F1-0BBE-485D-8E61-77FCC1CB6308}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quadratic", "2022-12-09-Big-O-Notation\Quadratic\Quadratic.csproj", "{3864AA23-5A37-4E4F-9324-E68BC78B7AD4}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Exponential", "2022-12-09-Big-O-Notation\Exponential\Exponential.csproj", "{3E1B73A9-BC6C-42D9-BB90-C4568753F406}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Linear", "2022-12-09-Big-O-Notation\Linear\Linear.csproj", "{EDAF8432-6D21-4FCA-84F6-1A71AA9E0237}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Constant", "2022-12-09-Big-O-Notation\Constant\Constant.csproj", "{EB616A5C-E246-4278-B75E-956D9A239D24}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{84D0E2A6-F29D-4E7A-A9A7-7B3B189858B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{84D0E2A6-F29D-4E7A-A9A7-7B3B189858B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{84D0E2A6-F29D-4E7A-A9A7-7B3B189858B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{84D0E2A6-F29D-4E7A-A9A7-7B3B189858B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{88871D7B-C1E5-40A9-99D5-C4728F4F9F34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{88871D7B-C1E5-40A9-99D5-C4728F4F9F34}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{88871D7B-C1E5-40A9-99D5-C4728F4F9F34}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{88871D7B-C1E5-40A9-99D5-C4728F4F9F34}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{738D63F4-EC3C-4228-8CDD-49F225D63F50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{738D63F4-EC3C-4228-8CDD-49F225D63F50}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{738D63F4-EC3C-4228-8CDD-49F225D63F50}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{738D63F4-EC3C-4228-8CDD-49F225D63F50}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{687246E4-702E-40D2-A00F-A6D8933EFE76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{687246E4-702E-40D2-A00F-A6D8933EFE76}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{687246E4-702E-40D2-A00F-A6D8933EFE76}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{687246E4-702E-40D2-A00F-A6D8933EFE76}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3864AA23-5A37-4E4F-9324-E68BC78B7AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3864AA23-5A37-4E4F-9324-E68BC78B7AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3864AA23-5A37-4E4F-9324-E68BC78B7AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3864AA23-5A37-4E4F-9324-E68BC78B7AD4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3E1B73A9-BC6C-42D9-BB90-C4568753F406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3E1B73A9-BC6C-42D9-BB90-C4568753F406}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3E1B73A9-BC6C-42D9-BB90-C4568753F406}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3E1B73A9-BC6C-42D9-BB90-C4568753F406}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EDAF8432-6D21-4FCA-84F6-1A71AA9E0237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EDAF8432-6D21-4FCA-84F6-1A71AA9E0237}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EDAF8432-6D21-4FCA-84F6-1A71AA9E0237}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EDAF8432-6D21-4FCA-84F6-1A71AA9E0237}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EB616A5C-E246-4278-B75E-956D9A239D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EB616A5C-E246-4278-B75E-956D9A239D24}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EB616A5C-E246-4278-B75E-956D9A239D24}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EB616A5C-E246-4278-B75E-956D9A239D24}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{84D0E2A6-F29D-4E7A-A9A7-7B3B189858B4} = {D9274304-4A5B-457C-9F94-0D43FCB34306}
|
||||
{88871D7B-C1E5-40A9-99D5-C4728F4F9F34} = {D9274304-4A5B-457C-9F94-0D43FCB34306}
|
||||
{738D63F4-EC3C-4228-8CDD-49F225D63F50} = {D9274304-4A5B-457C-9F94-0D43FCB34306}
|
||||
{687246E4-702E-40D2-A00F-A6D8933EFE76} = {D9274304-4A5B-457C-9F94-0D43FCB34306}
|
||||
{3864AA23-5A37-4E4F-9324-E68BC78B7AD4} = {44A151F1-0BBE-485D-8E61-77FCC1CB6308}
|
||||
{3E1B73A9-BC6C-42D9-BB90-C4568753F406} = {44A151F1-0BBE-485D-8E61-77FCC1CB6308}
|
||||
{EDAF8432-6D21-4FCA-84F6-1A71AA9E0237} = {44A151F1-0BBE-485D-8E61-77FCC1CB6308}
|
||||
{EB616A5C-E246-4278-B75E-956D9A239D24} = {44A151F1-0BBE-485D-8E61-77FCC1CB6308}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4009C08A-12EC-4A91-9145-57C7F0B5124C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in a new issue