C# - Performance of reusing object with string properties vs creating new instance -


suppose have class contains 3 string properties. new instances of being created several times needlessly throughout application. class use these 3 strings perform linq query like:

where(string1 == this.string1).where(string2 == this.string2).where(string3 == this.string3)

instead of creating instance every single time object needed, i'm thinking modifying classes use type store 1 instance of object , modify string properties before using each time. right way optimize class? basically, i'm trying avoid overhead of creating instance , allocating memory strings every time.

is there faster way perform above linq query instead?

yes is. unless there're plenty of objects, difference in performance negligible.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -