This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
Original Post: What's wrong with this code - #6
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
After a long hiatus, here's the next entry in my not-really-regular-enough-to-honestly-be-called-periodic-(though-I-try-to-keep-up-a-somewhat-reasonable-schedule-I-don't-seem-to-keep-it-since-I'm-lazy-are-you-still-reading-this)-series about C# code.
Anyway, here's some code that I've seen a fair bit, and written myself:
class Notifier
{
ArrayList items = new ArrayList();
public void Add(object o) {
lock (this) {
items.Add(o);
}
}
}
This code will work fine, but it has a latent issue. What is the issue, and how should it be addressed?