using System.Collections.Generic;
using System.Threading.Tasks;
public int[] cache = new int[3];
public int[] MemoryArray ;
static void Main(string[] args)
Program obj = new Program();
Console.Write("Enter length of an array : ");
lenght = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("array length : {0}", lenght);
obj.MemoryArray = new int[lenght];
Console.WriteLine("Enter number in array : ");
for (int i = 0; i < obj.MemoryArray.Length; i++)
a = Convert.ToInt32(Console.ReadLine());
if (obj.MemoryArray.Length <= 0)
Console.WriteLine("Enter minimum one arguments....");
if (MemoryArray.Length < 3)
for (int i = 0; i < MemoryArray.Length; i++)
cache[i] = MemoryArray[i];
for (int i = 0; i < cache.Length; i++)
cache[i] = MemoryArray[i];
for (int i = 0; i < cache.Length; i++)
void updateCache(int x, int index)
for (int i = 0; i < MemoryArray.Length; i++)
if (cache[0] == MemoryArray[i] && one == 0)
if (cache[1] == MemoryArray[i] && one == 0)
if (cache[2] == MemoryArray[i] && one == 0)
if ((one > two && one > three) || one == 0)
else if (two > one && two > three)
else if (three > one && three > two)
for (int i = 3; i < MemoryArray.Length; i++)
Console.WriteLine("Right now values in cache: " + cache[0] + " " + cache[1] + " " + cache[2]);
if (wasInCache(MemoryArray[i]))
updateCache(MemoryArray[i], i);
Console.WriteLine("Total Hit counts = " + hitCount);
Console.WriteLine("Total miss counts = " + missCount);