yield returns within lock statement
        Posted  
        
            by DayOne
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by DayOne
        
        
        
        Published on 2010-05-17T08:30:24Z
        Indexed on 
            2010/05/17
            8:50 UTC
        
        
        Read the original article
        Hit count: 197
        
c#
Hi eveybody, if i have a yield return in a lock statement does the lock get taken out on each yield (5 times in the example below) or only once for all the items in the list?
Thanks
    private List<string> _data = new List<string>(){"1","2","3","4","5"};
    private object _locker =new object();
    public IEnumerable<string> GetData()
    {
        lock (_locker)
        {
            foreach (string s in _data)
            {
                yield return s;
            }
        }
    }
© Stack Overflow or respective owner