I see this a lot in some new code I’ve inherited:
DataRow row = Method.dtContainer.NewRow();
But then row is never added to the table or even used after that. ReSharper shows it as grey and safe to remove. However, should I remove the entire line or just the variable assigning? Anotherwords, does calling NewRow do anything to the table or does it just return a new object that can then later be added to the DataTable? I’ve checked and it isn’t accessed anywhere else through reflection, gotos, etc.
Thanks.
Resharper is right.
NewRow()just returns a new row that has the structure(schema) of theDataTableinstance.Usually, the new row is populated with data and added to the
DataTable, like so:If it is not used in any way, it’s safe to remove that line.