diff --git a/Lesson01/Lesson01/Program.cs b/Lesson01/Lesson01/Program.cs index 2774e62..77dacd2 100644 --- a/Lesson01/Lesson01/Program.cs +++ b/Lesson01/Lesson01/Program.cs @@ -7,11 +7,9 @@ static void Main(string[] args) Console.WriteLine("Hello, World!"); } - // Homework - // Complete the following method public static int Add(int a, int b) { - return 0; + return a + b; } } } \ No newline at end of file diff --git a/Lesson04/Lesson04.sln b/Lesson04/Lesson04.sln new file mode 100644 index 0000000..b4af16e --- /dev/null +++ b/Lesson04/Lesson04.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lesson04", "Lesson04\Lesson04.csproj", "{2BD7DB44-DD50-4842-8301-2355386ED7AF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2BD7DB44-DD50-4842-8301-2355386ED7AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BD7DB44-DD50-4842-8301-2355386ED7AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BD7DB44-DD50-4842-8301-2355386ED7AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BD7DB44-DD50-4842-8301-2355386ED7AF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {69432ABB-02AF-4CEB-ADBD-A1736AFB0F56} + EndGlobalSection +EndGlobal diff --git a/Lesson04/Lesson04/Lesson04.csproj b/Lesson04/Lesson04/Lesson04.csproj new file mode 100644 index 0000000..f02677b --- /dev/null +++ b/Lesson04/Lesson04/Lesson04.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/Lesson04/Lesson04/Program.cs b/Lesson04/Lesson04/Program.cs new file mode 100644 index 0000000..afbfe1c --- /dev/null +++ b/Lesson04/Lesson04/Program.cs @@ -0,0 +1,97 @@ +namespace Lesson04 +{ + internal class Program + { + public delegate bool Predicate1(int t, int max); + + static void Main(string[] args) + { + int[] numbers = { 1, 9, 3, 4, -5, -6, -7, 8 }; + Where(numbers, NegativeNumbers); + } + static void Count(int[] number, Predicate predicate) + { + int counter = 0; + foreach (int i in number) + { + if (predicate(i)) + { + counter++; + } + } + Console.WriteLine(counter); + } + static void Max(int[] number, Predicate1 predicate) + { + int max = 0; + for (int i = 0; i < number.Length; ++i) + { + if (predicate(max, number[i])) + { + max = number[i]; + } + } + Console.WriteLine(max); + } + static void Min(int[] number, Predicate1 predicate) + { + int min = number[0]; + for (int i = 1; i < number.Length - 1; ++i) + { + if (predicate(min, number[i])) + { + min = number[i]; + } + } + Console.WriteLine(min); + } + static void Where(int[] number, Predicate predicate) + { + List numbers = new List(); + for (int i = 0; i < number.Length; ++i) + { + if (predicate(number[i])) + { + numbers.Add(number[i]); + } + } + foreach (int i in numbers) + { + Console.WriteLine(i); + } + } + static bool NegativeNumbers(int num) + { + if (num < 0) + { + return true; + } + return false; + } + static bool MinMax(int num1, int max) + { + if (num1 < max) + { + return true; + } + return false; + } + static bool Positive(int number) + { + if (number < 0) + { + return false; + } + return true; + } + static bool MinNumber(int number, int min) + { + if (min < number) + { + return true; + } + return false; + } + } +} +