-
Notifications
You must be signed in to change notification settings - Fork 6
Abdurakhmon (Homework) #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| namespace Lesson04 | ||
| { | ||
| internal class Program | ||
| { | ||
| public delegate bool Predicate1<T>(int t, int max); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Predicate1<T> degani bu T toifasi xozircha noma'lum, kelajakda bu delegatdan foydalanilganda, ma'lum qilinadi foydalanuvchini oz'i. Lekin, bu toifa delegat tomondan umuman ishlatilmayapti, bu degani bu generic toifa mutlaqo keraksiz. |
||
|
|
||
| static void Main(string[] args) | ||
| { | ||
| int[] numbers = { 1, 9, 3, 4, -5, -6, -7, 8 }; | ||
| Where(numbers, NegativeNumbers); | ||
| } | ||
| static void Count(int[] number, Predicate<int> predicate) | ||
| { | ||
| int counter = 0; | ||
| foreach (int i in number) | ||
| { | ||
| if (predicate(i)) | ||
| { | ||
| counter++; | ||
| } | ||
| } | ||
| Console.WriteLine(counter); | ||
| } | ||
| static void Max(int[] number, Predicate1<int> 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<int> 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<int> predicate) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where metodini qaytaruv toifasi int massivi bo'lishi kerak. number parametirini nomida "s" xarfi qolib ketgan. |
||
| { | ||
| List<int> numbers = new List<int>(); | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bool qaytaradigan metod va o'zgaruvchanlar odatda nomi savol asosida beriladi. Misol uchun: IsNegative -> Manfiymi? IsPositive -> Musbatmi? IsEven -> Juftmi va xokazo... Bu kodni sifatini oshiradi, sababi metod faqat ikta qiymat qaytaradi, metodni chaqirgan odam birdanigi bu metod nima qaytarishi tushuna oladi. |
||
| { | ||
| if (num < 0) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
|
Comment on lines
+65
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug tekshiruvni undan-da osonlashtirsa ham bo'ladi. |
||
| } | ||
| static bool MinMax(int num1, int max) | ||
| { | ||
| if (num1 < max) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
|
Comment on lines
+73
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ternary operator ishlatsa bo'ladi. |
||
| } | ||
| static bool Positive(int number) | ||
| { | ||
| if (number < 0) | ||
| { | ||
| return false; | ||
| } | ||
| return true; | ||
|
Comment on lines
+81
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tekshiruvni qisqartirsa bo'ladi. |
||
| } | ||
| static bool MinNumber(int number, int min) | ||
| { | ||
| if (min < number) | ||
| { | ||
| return true; | ||
| } | ||
| return false; | ||
|
Comment on lines
+89
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ternary operator yaxshiroq to'gri keladi. |
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug fayl o'zgarishi kerak emas!