From f50833a27612d8563830d1719524e2d1df4bfae1 Mon Sep 17 00:00:00 2001 From: strwbrry1 Date: Sun, 31 Mar 2024 11:56:01 +0400 Subject: [PATCH 1/2] lab-3 done --- .../AbstractCompany.cs | 67 +++++++ .../ArrayGenericObjects.cs | 95 ++++++++++ .../CollectionGenericObjects/Harbor.cs | 60 +++++++ .../ICollectionGenericObjects.cs | 24 +++ .../Catamaran/FormBoatColletion.Designer.cs | 169 ++++++++++++++++++ Catamaran/Catamaran/FormBoatColletion.cs | 156 ++++++++++++++++ Catamaran/Catamaran/FormBoatColletion.resx | 120 +++++++++++++ Catamaran/Catamaran/FormCatamaran.Designer.cs | 28 --- Catamaran/Catamaran/FormCatamaran.cs | 46 ++--- Catamaran/Catamaran/Program.cs | 2 +- 10 files changed, 704 insertions(+), 63 deletions(-) create mode 100644 Catamaran/Catamaran/CollectionGenericObjects/AbstractCompany.cs create mode 100644 Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs create mode 100644 Catamaran/Catamaran/CollectionGenericObjects/Harbor.cs create mode 100644 Catamaran/Catamaran/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 Catamaran/Catamaran/FormBoatColletion.Designer.cs create mode 100644 Catamaran/Catamaran/FormBoatColletion.cs create mode 100644 Catamaran/Catamaran/FormBoatColletion.resx diff --git a/Catamaran/Catamaran/CollectionGenericObjects/AbstractCompany.cs b/Catamaran/Catamaran/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..f8b4b77 --- /dev/null +++ b/Catamaran/Catamaran/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,67 @@ +using Catamaran.Drawings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Catamaran.CollectionGenericObjects +{ + public abstract class AbstractCompany + { + protected readonly int _placeSizeWidth = 180; + + protected readonly int _placeSizeHeight = 80; + + protected readonly int _pictureWidth; + + protected readonly int _pictureHeight; + + protected ICollectionGenericObjects? _collection = null; + + private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight / 2) ; + + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + { + _pictureHeight = picHeight; + _pictureWidth = picWidth; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + public static int operator +(AbstractCompany company, DrawingBoat boat) + { + return company._collection.Insert(boat); + } + + public static DrawingBoat operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + + public DrawingBoat? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawingBoat? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + + protected abstract void DrawBackground(Graphics g); + + protected abstract void SetObjectsPosition(); + } +} diff --git a/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs b/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs new file mode 100644 index 0000000..8131fd0 --- /dev/null +++ b/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Catamaran.CollectionGenericObjects +{ + public class ArrayGenericObjects : ICollectionGenericObjects + where T : class + { + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T[value]; + } + } + } + } + + public ArrayGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + return _collection[position]; + } + + public int Insert(T obj) + { + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + return -1; + } + + public int Insert(T obj, int position) + { + if (position < Count) + { + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + else + { + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + } + } + + return -1; + } + + public T? Remove(int position) + { + if (position > Count || position < 0) + { + + return null; + } + T? obj = _collection[position]; + _collection[position] = null; + return obj; + } + + } +} diff --git a/Catamaran/Catamaran/CollectionGenericObjects/Harbor.cs b/Catamaran/Catamaran/CollectionGenericObjects/Harbor.cs new file mode 100644 index 0000000..cefe5f2 --- /dev/null +++ b/Catamaran/Catamaran/CollectionGenericObjects/Harbor.cs @@ -0,0 +1,60 @@ +using Catamaran.Drawings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Catamaran.CollectionGenericObjects +{ + public class Harbor : AbstractCompany + { + public Harbor(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + + } + + protected override void DrawBackground(Graphics g) + { + Pen pen = new Pen(Color.Black, 4f); + for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++) + { + g.DrawLine(pen, 0, _pictureHeight - i * _placeSizeHeight * 2, _placeSizeWidth * (_pictureWidth / _placeSizeWidth), _pictureHeight - i * _placeSizeHeight * 2); + for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; j++) + { + g.DrawLine(pen, _placeSizeWidth * j, _pictureHeight - i * _placeSizeHeight * 2, _placeSizeWidth * j, _pictureHeight - i * _placeSizeHeight * 2 - _placeSizeHeight); + } + } + } + + + protected override void SetObjectsPosition() + { + int curPosX = 0; + int curPosY = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (curPosX > _pictureWidth / _placeSizeWidth) + { + return; + } + if (_collection?.Get(i) != null) + { + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(curPosX * _placeSizeWidth + 20, curPosY * _placeSizeHeight * -2 + (_pictureHeight - 60) ); + } + + if (curPosX < _pictureWidth / _placeSizeWidth - 1) + { + curPosX++; + } + else + { + curPosX = 0; + curPosY++; + } + } + } + } +} diff --git a/Catamaran/Catamaran/CollectionGenericObjects/ICollectionGenericObjects.cs b/Catamaran/Catamaran/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..dea89d7 --- /dev/null +++ b/Catamaran/Catamaran/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Catamaran.CollectionGenericObjects +{ + public interface ICollectionGenericObjects + where T : class + { + int Count { get; } + + int SetMaxCount { set; } + + int Insert(T obj); + + int Insert(T obj, int position); + + T? Remove(int position); + + T? Get(int position); + } +} diff --git a/Catamaran/Catamaran/FormBoatColletion.Designer.cs b/Catamaran/Catamaran/FormBoatColletion.Designer.cs new file mode 100644 index 0000000..a1e3696 --- /dev/null +++ b/Catamaran/Catamaran/FormBoatColletion.Designer.cs @@ -0,0 +1,169 @@ +namespace Catamaran +{ + partial class FormBoatColletion + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBox1 = new GroupBox(); + UpdateButton = new Button(); + GoToTestButton = new Button(); + DeleteButton = new Button(); + maskedTextBox = new MaskedTextBox(); + AddCatamaranButton = new Button(); + AddBoatButton = new Button(); + InstrumentBox = new ComboBox(); + pictureBox = new PictureBox(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBox1 + // + groupBox1.Controls.Add(UpdateButton); + groupBox1.Controls.Add(GoToTestButton); + groupBox1.Controls.Add(DeleteButton); + groupBox1.Controls.Add(maskedTextBox); + groupBox1.Controls.Add(AddCatamaranButton); + groupBox1.Controls.Add(AddBoatButton); + groupBox1.Controls.Add(InstrumentBox); + groupBox1.Dock = DockStyle.Right; + groupBox1.Location = new Point(809, 0); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(237, 642); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "Инструменты"; + // + // UpdateButton + // + UpdateButton.Location = new Point(6, 565); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(225, 38); + UpdateButton.TabIndex = 6; + UpdateButton.Text = "Обновить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // GoToTestButton + // + GoToTestButton.Location = new Point(12, 355); + GoToTestButton.Name = "GoToTestButton"; + GoToTestButton.Size = new Size(225, 38); + GoToTestButton.TabIndex = 5; + GoToTestButton.Text = "Передать на тесты"; + GoToTestButton.UseVisualStyleBackColor = true; + GoToTestButton.Click += GoToTestButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(6, 238); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(225, 38); + DeleteButton.TabIndex = 4; + DeleteButton.Text = "Удалить лодку"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 205); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(225, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // AddCatamaranButton + // + AddCatamaranButton.Location = new Point(6, 104); + AddCatamaranButton.Name = "AddCatamaranButton"; + AddCatamaranButton.Size = new Size(225, 38); + AddCatamaranButton.TabIndex = 2; + AddCatamaranButton.Text = "Добавить катамаран"; + AddCatamaranButton.UseVisualStyleBackColor = true; + AddCatamaranButton.Click += AddCatamaranButton_Click; + // + // AddBoatButton + // + AddBoatButton.Location = new Point(6, 60); + AddBoatButton.Name = "AddBoatButton"; + AddBoatButton.Size = new Size(225, 38); + AddBoatButton.TabIndex = 1; + AddBoatButton.Text = "Добавить лодку"; + AddBoatButton.UseVisualStyleBackColor = true; + AddBoatButton.Click += AddBoatButton_Click; + // + // InstrumentBox + // + InstrumentBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + InstrumentBox.AutoCompleteCustomSource.AddRange(new string[] { "Хранилище" }); + InstrumentBox.DropDownStyle = ComboBoxStyle.DropDownList; + InstrumentBox.FormattingEnabled = true; + InstrumentBox.Items.AddRange(new object[] { "Хранилище" }); + InstrumentBox.Location = new Point(6, 26); + InstrumentBox.Name = "InstrumentBox"; + InstrumentBox.Size = new Size(225, 28); + InstrumentBox.TabIndex = 0; + InstrumentBox.SelectedIndexChanged += InstrumentBox_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(809, 642); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBoatColletion + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1046, 642); + Controls.Add(pictureBox); + Controls.Add(groupBox1); + Name = "FormBoatColletion"; + Text = "Коллекция лодок"; + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBox1; + private ComboBox InstrumentBox; + private Button AddBoatButton; + private Button AddCatamaranButton; + private PictureBox pictureBox; + private MaskedTextBox maskedTextBox; + private Button DeleteButton; + private Button GoToTestButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/Catamaran/Catamaran/FormBoatColletion.cs b/Catamaran/Catamaran/FormBoatColletion.cs new file mode 100644 index 0000000..ff418d8 --- /dev/null +++ b/Catamaran/Catamaran/FormBoatColletion.cs @@ -0,0 +1,156 @@ +using Catamaran.CollectionGenericObjects; +using Catamaran.Drawings; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Catamaran +{ + public partial class FormBoatColletion : Form + { + + private AbstractCompany? _company = null; + + + + public FormBoatColletion() + { + InitializeComponent(); + } + + private void InstrumentBox_SelectedIndexChanged(object sender, EventArgs e) + { + switch (InstrumentBox.Text) + { + case "Хранилище": + _company = new Harbor(pictureBox.Width, pictureBox.Height, new ArrayGenericObjects()); + break; + } + } + + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + DrawingBoat drawingBoat; + Random random = new(); + + switch (type) + { + case nameof(DrawingBoat): + drawingBoat = new DrawingBoat(random.Next(100, 500), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawingCatamaran): + drawingBoat = new DrawingCatamaran(random.Next(100, 500), random.Next(1000, 3000), GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawingBoat >= 0) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + private void AddBoatButton_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingBoat)); + } + + private void AddCatamaranButton_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingCatamaran)); + } + + + + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + return color; + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text)) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } + + private void GoToTestButton_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawingBoat? boat = null; + int counter = 100; + while (boat == null) + { + boat = _company.GetRandomObject(); + + counter--; + if (counter <= 0) break; + } + + if (boat == null) + { + return; + } + + FormCatamaran form = new() + { + SetBoat = boat + }; + form.ShowDialog(); + } + } +} diff --git a/Catamaran/Catamaran/FormBoatColletion.resx b/Catamaran/Catamaran/FormBoatColletion.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Catamaran/Catamaran/FormBoatColletion.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Catamaran/Catamaran/FormCatamaran.Designer.cs b/Catamaran/Catamaran/FormCatamaran.Designer.cs index 13d67bd..cbfb19a 100644 --- a/Catamaran/Catamaran/FormCatamaran.Designer.cs +++ b/Catamaran/Catamaran/FormCatamaran.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBox1 = new PictureBox(); - CreateButton = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); - CreateBoat_button = new Button(); StrategyBox = new ComboBox(); StepButton = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); @@ -49,17 +47,6 @@ pictureBox1.TabIndex = 0; pictureBox1.TabStop = false; // - // CreateButton - // - CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - CreateButton.Location = new Point(12, 456); - CreateButton.Name = "CreateButton"; - CreateButton.Size = new Size(168, 29); - CreateButton.TabIndex = 1; - CreateButton.Text = "Создать катамаран"; - CreateButton.UseVisualStyleBackColor = true; - CreateButton.Click += CreateButton_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // CreateBoat_button - // - CreateBoat_button.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - CreateBoat_button.Location = new Point(186, 456); - CreateBoat_button.Name = "CreateBoat_button"; - CreateBoat_button.Size = new Size(168, 29); - CreateBoat_button.TabIndex = 6; - CreateBoat_button.Text = "Создать лодку"; - CreateBoat_button.UseVisualStyleBackColor = true; - CreateBoat_button.Click += CreateBoat_button_Click; - // // StrategyBox // StrategyBox.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -148,12 +124,10 @@ ClientSize = new Size(668, 497); Controls.Add(StepButton); Controls.Add(StrategyBox); - Controls.Add(CreateBoat_button); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(CreateButton); Controls.Add(pictureBox1); Name = "FormCatamaran"; Text = "Катамаран"; @@ -165,12 +139,10 @@ #endregion private PictureBox pictureBox1; - private Button CreateButton; private Button buttonLeft; private Button buttonDown; private Button buttonRight; private Button buttonUp; - private Button CreateBoat_button; private ComboBox StrategyBox; private Button StepButton; } diff --git a/Catamaran/Catamaran/FormCatamaran.cs b/Catamaran/Catamaran/FormCatamaran.cs index 2b06c83..04b7411 100644 --- a/Catamaran/Catamaran/FormCatamaran.cs +++ b/Catamaran/Catamaran/FormCatamaran.cs @@ -25,6 +25,18 @@ namespace Catamaran _strategy = null; } + public DrawingBoat SetBoat + { + set + { + _drawingBoat = value; + _drawingBoat.SetPictureSize(pictureBox1.Width, pictureBox1.Height); + StrategyBox.Enabled = true; + _strategy = null; + Draw(); + } + } + private void Draw() { if (_drawingBoat == null) return; @@ -35,40 +47,6 @@ namespace Catamaran pictureBox1.Image = bmp; } - private void CreateObject(string type) - { - Random random = new Random(); - - switch (type) - { - case nameof(DrawingBoat): - _drawingBoat = new DrawingBoat(random.Next(100, 500), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - case nameof(DrawingCatamaran): - _drawingBoat = new DrawingCatamaran(random.Next(100, 500), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - - _drawingBoat.SetPictureSize(pictureBox1.Width, pictureBox1.Height); - _drawingBoat.SetPosition(random.Next(10, 600), random.Next(10, 600)); - Draw(); - } - - private void CreateButton_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingCatamaran)); - } - - private void CreateBoat_button_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingBoat)); - } - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawingBoat == null) return; diff --git a/Catamaran/Catamaran/Program.cs b/Catamaran/Catamaran/Program.cs index cad1371..f607f17 100644 --- a/Catamaran/Catamaran/Program.cs +++ b/Catamaran/Catamaran/Program.cs @@ -11,7 +11,7 @@ namespace Catamaran // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCatamaran()); + Application.Run(new FormBoatColletion()); } } } \ No newline at end of file -- 2.25.1 From 7220e5c2295986ff55f664f07ad15b2b07ad0a59 Mon Sep 17 00:00:00 2001 From: strwbrry1 Date: Wed, 3 Apr 2024 14:04:19 +0400 Subject: [PATCH 2/2] added missing logic --- .../CollectionGenericObjects/ArrayGenericObjects.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs b/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs index 8131fd0..ac72605 100644 --- a/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs +++ b/Catamaran/Catamaran/CollectionGenericObjects/ArrayGenericObjects.cs @@ -38,7 +38,11 @@ namespace Catamaran.CollectionGenericObjects public T? Get(int position) { - return _collection[position]; + if (position >= 0 && position < Count) + { + return _collection[position]; + } + return null; } public int Insert(T obj) -- 2.25.1