Skip to content

Commit

Permalink
code from 05.12.23 lecture
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletSurge committed Dec 6, 2023
1 parent c9c8f78 commit 83b632b
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 39 deletions.
10 changes: 10 additions & 0 deletions DigitalCathedral.Task1/DigitalCathedral.Task1.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions DigitalCathedral.Task1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// See https://aka.ms/new-console-template for more information

using DigitalCathedral.Task1;

try
{
Student s1 = new Student("", "", "", "", "", 3);
Student s2 = new Student("", "", "", "", "", 3);
Console.WriteLine(s1.Equals(s2));
Student st = new Student("Ivanov", "Ivan", "Ivanovich", "M1O-301B-21", "1234-123-12", 3);

Console.WriteLine("No exceptions were thrown");
}
catch (ArgumentNullException ex)
{
//
Console.WriteLine(ex.Message);
}
catch (ArgumentException ex)
{
//
Console.WriteLine(ex.Message);
}

Console.WriteLine("after try/catch...");
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DigitalCathedral;
namespace DigitalCathedral.Task1;

public sealed class Student:
IEquatable<Student>
Expand All @@ -8,15 +8,15 @@ public sealed class Student:
private readonly string _name;
private readonly string _patronymic;
private readonly string _group;
private readonly string _zachetka;
private readonly string _recordBookId;
private readonly int _course;

public Student(
string? surname,
string? name,
string? patronymic,
string? group,
string? zachetka,
string? recordBookId,
int course)
{
if (surname is null)
Expand All @@ -28,7 +28,7 @@ public Student(
_name = name ?? throw new ArgumentNullException(nameof(name));
_patronymic = patronymic ?? throw new ArgumentNullException(nameof(patronymic));
_group = group ?? throw new ArgumentNullException(nameof(group));
_zachetka = zachetka ?? throw new ArgumentNullException(nameof(zachetka));
_recordBookId = recordBookId ?? throw new ArgumentNullException(nameof(recordBookId));
// if (!(course >= 1 && course <= 4))
if (course < 1 || course > 4)
{
Expand All @@ -49,15 +49,15 @@ public Student(
public string Group =>
_group;

public string Zachetka =>
_zachetka;
public string RecordBookId =>
_recordBookId;

public int Course =>
_course;

public override string ToString()
{
return "";
return $"Surname = \"{Surname}\", Name = \"{Name}\", Patronymic = \"{Patronymic}\", Group = \"{Group}\", Record book id = \"{RecordBookId}\", Course = {Course}";
}

public override int GetHashCode()
Expand All @@ -67,7 +67,7 @@ public override int GetHashCode()
result.Add(_name);
result.Add(_patronymic);
result.Add(_group);
result.Add(_zachetka);
result.Add(_recordBookId);
result.Add(_course);
return result.ToHashCode();
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public bool Equals(
_name.Equals(student._name) &&
_patronymic.Equals(student._patronymic) &&
_group.Equals(student._group) &&
_zachetka.Equals(student._zachetka) &&
_recordBookId.Equals(student._recordBookId) &&
_course.Equals(student._course);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DigitalCathedral;
namespace DigitalCathedral.Task2;

public static class CombinatoricsExtensions
{
Expand Down
10 changes: 10 additions & 0 deletions DigitalCathedral.Task2/DigitalCathedral.Task2.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>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace DigitalCathedral;
namespace DigitalCathedral.Task2;

public sealed class IntEqualityComparer : IEqualityComparer<int>
{

private const int EventIntHashCode = 0;

public bool Equals(
Expand All @@ -25,4 +26,5 @@ public int GetHashCode(
}
return obj.GetHashCode();
}

}
12 changes: 12 additions & 0 deletions DigitalCathedral.Task2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using DigitalCathedral.Task2;

try
{
IEqualityComparer<int> equalityComparer = new IntEqualityComparer();
var values = new int [] { 1, 2, 3, 4, 5 };
values.GetCombinations(3, equalityComparer);
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
}
18 changes: 18 additions & 0 deletions DigitalCathedral.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalCathedral", "DigitalCathedral\DigitalCathedral.csproj", "{1D8020D4-5048-4BBB-A779-44E7C3AD43CB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tasks", "Tasks", "{8193D3C5-610D-4FEF-B2C2-8E41D6594161}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalCathedral.Task1", "DigitalCathedral.Task1\DigitalCathedral.Task1.csproj", "{8022E880-A4E4-441B-8D90-195C4382F1C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalCathedral.Task2", "DigitalCathedral.Task2\DigitalCathedral.Task2.csproj", "{26461CE6-A23D-4B47-B9B4-C1354CBBC946}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +18,17 @@ Global
{1D8020D4-5048-4BBB-A779-44E7C3AD43CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D8020D4-5048-4BBB-A779-44E7C3AD43CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D8020D4-5048-4BBB-A779-44E7C3AD43CB}.Release|Any CPU.Build.0 = Release|Any CPU
{8022E880-A4E4-441B-8D90-195C4382F1C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8022E880-A4E4-441B-8D90-195C4382F1C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8022E880-A4E4-441B-8D90-195C4382F1C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8022E880-A4E4-441B-8D90-195C4382F1C8}.Release|Any CPU.Build.0 = Release|Any CPU
{26461CE6-A23D-4B47-B9B4-C1354CBBC946}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26461CE6-A23D-4B47-B9B4-C1354CBBC946}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26461CE6-A23D-4B47-B9B4-C1354CBBC946}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26461CE6-A23D-4B47-B9B4-C1354CBBC946}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8022E880-A4E4-441B-8D90-195C4382F1C8} = {8193D3C5-610D-4FEF-B2C2-8E41D6594161}
{26461CE6-A23D-4B47-B9B4-C1354CBBC946} = {8193D3C5-610D-4FEF-B2C2-8E41D6594161}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions DigitalCathedral/IEnumerableImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;

namespace DigitalCathedral;

public class IEnumerableImpl:
IEnumerable<int>
{

private readonly int[] _values = new[] { 1, 2, 3, 4, 5 };

IEnumerator IEnumerable.GetEnumerator()
{
return _values.GetEnumerator();
}

public IEnumerator<int> GetEnumerator()
{
for (var i = 0; i < _values.Length; i++)
{
yield return _values[i];
}
}

}
47 changes: 19 additions & 28 deletions DigitalCathedral/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
// { +k, x > y
// IComparable, IComparable<T>, IComparer<T>

using System.Collections;
using DigitalCathedral;
//
// int value = 11;
Expand Down Expand Up @@ -266,27 +267,7 @@
// // TODO: work with value
// }
//
// Student s1 = new Student("", "", "", "", "", 3);
// Student s2 = new Student("", "", "", "", "", 3);
// Console.WriteLine(s1.Equals(s2));
//
// try
// {
// Student st = new Student("Ivanov", "Ivan", "Ivanovich", "M1O-301B-21", "1234-123-12", 3);
//
// Console.WriteLine("No exceptions were thrown");
// }
// catch (ArgumentNullException ex)
// {
// //
// Console.WriteLine(ex.Message);
// }
// catch (ArgumentException ex)
// {
// //
// Console.WriteLine(ex.Message);
// }
// Console.WriteLine("after try/catch...");

//
// var fraction = new Fraction(2, 5);
// var fraction2 = new Fraction(1, 7);
Expand All @@ -295,14 +276,24 @@
// var multiplicationResult = Fraction.Multiplication(fraction, fraction2);
//
// Console.WriteLine(fraction.CompareTo(fraction2));
{
int value = 10;
object o = (object) value;
int value1 = (int) o;
Console.WriteLine(value1);
}

try
var impl = new IEnumerableImpl();
var iterator = ((IEnumerable)impl).GetEnumerator();
while (iterator.MoveNext())
{
IEqualityComparer<int> equalityComparer = new IntEqualityComparer();
var values = Enumerable.Range(1, 10).ToArray();
values.GetCombinations(3, equalityComparer);
Console.WriteLine((int)iterator.Current);
}
catch (ArgumentException ex)

foreach (var value in impl)
{
Console.WriteLine(ex.Message);
}
Console.WriteLine(value);
}

//IComparer<T>
//IEqualityComparer<int>;

0 comments on commit 83b632b

Please sign in to comment.