Archive for the ‘CSharp’ Category

C# Generics and anonymous methods

Friday, November 14th, 2008

I’ve never been much of a C# maven or anything, but I’ve really fallen in love with this construct in the language. One thing which I guess almost anyone does alot of is building a string, from a list of business objects. Let’s say you have a list of GUIDs, and you either want to display them, or build an SQL string from them for use in a query.

List<Guid> gs;
string s;

foreach (Guid g in gs) {
    s += "Id='" + g.ToString() + "' OR ";
}

if (result.Length > 0) {
    s = s.Substring(0, s.Length-3);
}

That’s some good ole fashioned string fucking, and since I’ve come over from HTML/JavaScript/(Classic) ASP/PHP, that’s bussiness as usual by all standards. But I’ve never liked several aspects of it.

(more…)