One of the neat things is that it is constantly suggesting better ways of coding or of structuring your code. I find myself learning about attributes of C# that I'd either forgotten, or hadn't know about.
I have a list of transactions that I want to add to the budget month container. Traditionally we might have done something like the following.
foreach (var transactionItem in items) { month.AddTransaction(transactionItem); }
This simply iterates over the collection of items, and for each one it calls the .AddTransaction method on the month.
My more modern method might be more like this:
items.ForEach(i => month.AddTransaction(i));
Resharper, though had a suggestion. Why not simplify that line even further? I'm game - so I clicked the suggestion. After all, there is always undo. This is the line;
items.ForEach(month.AddTransaction);
Simple, concise, and clear. I will confess that I had to run the unit test it in the debugger and inspect month's transactions just to make sure that the items had actually made it in there. Yup. Sweet.
No comments:
Post a Comment