Add storage class to store list in memory
This commit is contained in:
parent
b7e983070c
commit
f32cf745b6
2 changed files with 31 additions and 1 deletions
29
Storage.cs
Normal file
29
Storage.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace productlist
|
||||||
|
{
|
||||||
|
public static class Storage
|
||||||
|
{
|
||||||
|
private static List<Product> productStorageList = new List<Product>();
|
||||||
|
|
||||||
|
public static void Add(Product p) {
|
||||||
|
productStorageList.Add (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void listProducts() {
|
||||||
|
if (productStorageList.Count < 1) {
|
||||||
|
Console.WriteLine ("No Products found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (Product p in productStorageList) {
|
||||||
|
p.display ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void List() {
|
||||||
|
listProducts ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Product.cs" />
|
<Compile Include="Product.cs" />
|
||||||
<Compile Include="UI.cs" />
|
<Compile Include="UI.cs" />
|
||||||
|
<Compile Include="Storage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Reference in a new issue