Conversation
yurii-litvinov
left a comment
There was a problem hiding this comment.
Очень топорно и неаккуратно, но в целом так. Кстати, Dictionary бы лучше подошёл для хранения элементов вектора.
| namespace Test1._1Task1 | ||
| { | ||
|
|
||
| public class Vectors |
There was a problem hiding this comment.
Надо больше комментариев
|
|
||
| public class Vectors | ||
| { | ||
| public Dictionary<int, Vectors> VectorsDictionary { get; set; } |
There was a problem hiding this comment.
Словарь, который отображает число в Vectors, это типа дерево векторов? Что? :)
| VectorsDictionary.Add(index, vector); | ||
| } | ||
|
|
||
| public (int index, int number)[] Vector { get; set; } |
There was a problem hiding this comment.
Вообще, плохая идея предоставлять public-сеттеры ко всему, чему можно, это нарушает инкапсуляцию
| VectorsDictionary.Add(index, vector); | ||
| } | ||
|
|
||
| public void delete(Vectors vector, int index) |
There was a problem hiding this comment.
Методы в C# всегда именуются с заглавной
|
|
||
| public void delete(Vectors vector, int index) | ||
| { | ||
| VectorsDictionary.Add(index, vector); |
| /// сложение векторов | ||
| /// </summary> | ||
| /// <returns>вернет вектор сложения</returns> | ||
| public (int index, int number)[] Addition(Vectors vector1, Vectors vector2) |
There was a problem hiding this comment.
Стоит всегда, где это осмысленно, стремиться к замкнутости операций (то есть чтобы сложение двух векторов возвращало вектор)
| { | ||
| if (!CheckSize(vector1.Size, vector2.Size)) | ||
| { | ||
| //throw Exception; |
| } | ||
| } | ||
| return vector; | ||
| } |
There was a problem hiding this comment.
Копипастище :) Можно было просто инвертировать знаки и сложить
| vector[3] = (5, 1); | ||
| vector[4] = (6, 1); | ||
| vector[5] = (9, 2); | ||
| Assert.IsTrue(vector == vector1.Addition(vector1, vector2)); |
There was a problem hiding this comment.
Не-а, это будет ссылочное равенство. Assert.AreEqual бы помог, он сравнивает массивы поэлементно
No description provided.