When I was reading this tutorial I noticed the following performance tip about using structs in C#:
Unless you need reference type semantics, a class that is smaller than 16 bytes may be more efficiently handled by the system as a struct.
I looked for similar question in stackoverflow and I found some questions that talk about performance best practices in ADO.Net, Networking, Streams, but not about performance best practices in C# (The language).
I want to add another tip about using the integer types:
The runtime optimizes the performance of 32-bit integer types (Int32 and UInt32), so use those types for counters and other frequently accessed integral variables.
Simply: profile.
Every app is different. Taking time to reduce some code to make it "more efficient" is meaningless if that is not a bottleneck in you app. Also - you may even be making things worse if you don't have numbers to support changes.
In most cases IO is the pinch-point, so thinking about IO is a no-brainer. Ditto DB access. But beyond that: measure it.
Eric Lippert talks alot about optimization. I would read his blog.
I would check out Jon Skeet's blog also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With