Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Lesson01/Lesson01/Program.cs
Copy link
Copy Markdown
Contributor

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!

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
25 changes: 25 additions & 0 deletions Lesson04/Lesson04.sln
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
10 changes: 10 additions & 0 deletions Lesson04/Lesson04/Lesson04.csproj
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>
97 changes: 97 additions & 0 deletions Lesson04/Lesson04/Program.cs
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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Copy Markdown
Contributor

@Mirazyzz Mirazyzz Sep 23, 2023

Choose a reason for hiding this comment

The 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ternary operator yaxshiroq to'gri keladi.

}
}
}