I need to post some raw .NET code every so often or I get constipated. Actually, I've not been blogging or posting much code lately because I've been banging out so much code for The Man. Ironic.
Here's a little diddy to determine if an integer is odd or even. The scenario, we're painting a row of a Windows Form control and want to alternate row colors between lavender (my favorite) and white. The [e.Index & 1 == 0] does the trick in CSharp bristle fashion.
protected override void OnDrawItem(DrawItemEventArgs e, StreamsDataSet.dtResourcesRow dr)
{
Brush brushBack = (e.Index & 1) == 0 ? Brushes.Lavender : SystemBrushes.Window;
.....
}
Technorati Tags: .NET