No, you need to use a blocking block so that no one tries to read the array while some other process writes to it. Otherwise, you may have problems.
This is actually quite simple in C #, you can just do this:
Object lockObj = new Object();
int[] x = new int[5];
public void SetArrayVal(int ndx, int val)
{
if (ndx < 0 || ndx >= x.Length)
{
throw new ArgumentException("ndx was out of range", ndx);
}
lock (lockObj )
{
x[ndx] = val;
}
}
public int GetVal(int ndx)
{
if (ndx < 0 || ndx >= x.Length)
{
throw new ArgumentException("ndx was out of range", ndx);
}
lock (lockObj )
{
return x[ndx];
}
}
, , . .