I have a strongly-typed datatable and I search for a row by primary key (FyndBy) and them if the row exists I want to delete it. From a style perspective which of the methods below do you prefer?
MyDataRowType selectedRow = table.FindByTablePrimaryKey(something); if (selectedRow != null) selectedRow.Delete();
or
if (table.FindByTablePrimaryKey(something) != null) table.FindByTablePrimaryKey(something).Delete();
The technical reason for choosing the first one is that you’re using a simple pointer (usually just 4 bytes of memory) to store a reference to the row – that is, by using just 4 bytes you gain in not scanning the table again, which takes up a lot of resources (depending on table size, of course).