Can this code throw an exception?
public String[] GetPorts()
{
var sourceArray = Data;
var array = new String[sourceArray.Count];
for (int i = 0; i < array.Length; i++)
{
array[i] = Data[i][0];
}
return array;
}
Data is List<String[3]>
If
Datacan be changed from another thread, you’ve got a problem. For example, ifData‘s size may be changed during iteration, you may getIndexOutOfBoundException. Moreover, it’s possible thatDatadoesn’t support simultaneous reading and writing. (Writing may be done by other thread at the same time as you read it with the code you presented.)You ought to protect
Datawith a mutex.We could give you more information if we knew what data type is
Data.According to MSDN,
List<T>doesn’t support concurrent readers and writers. So you have to protect theDataif other code may write to it.