Alright, so here is the property I have
public List<String> names{
get{
lock(_names)
return _names;
}
set{
lock(_names)
_names = value
}
}
private List<String> _names;
and now say I do a foreach on names like this
foreach(String s in names)
{
Console.WriteLine(s);
}
My question is, is names
locked through the whole foreach
, or does it only lock
each time s
is set, then unlocks inside the foreach
.
If that's confusing, say I try to do this
foreach(String s in names)
{
lock(names)
Console.WriteLine(s);
}
Will I end up in a deadlock?