Adding Profile and ProfileList class

This commit is contained in:
Miskolczi Richárd
2023-03-24 11:14:49 +01:00
parent ef93530830
commit 911b3fc819
7 changed files with 109 additions and 30 deletions

View File

@@ -0,0 +1,62 @@
using System;
namespace Password_Manager
{
sealed class ProfileList
{
private Profile[] list;
public int Length
{
get
{
return this.list.Length;
}
}
public Profile this[int index]
{
get
{
return this.list[index];
}
}
public ProfileList()
{
this.list = new Profile[0];
}
public void Add(Profile p)
{
//grow the list by 1 and copy all existing items
Profile[] tmp = new Profile[this.Length + 1];
for (int i = 0; i < this.Length; i++)
{
tmp[i] = this[i];
}
this.list = tmp;
//--------------------------------------------------------
list[this.Length - 1] = p;
}
public void Remove(Profile p)
{
Profile[] tmp = new Profile[this.Length - 1];
for (int i = 0; i < tmp.Length; i++)
{
if (this[i] != p)
{
tmp[i] = this[i];
}
}
this.list = tmp;
}
}
}