I am working on an application which has classes like this :
public class ClassA
{
List<ClassB> _myList = new List<ClassB>();
public ClassA()
{
_myList.Add(new ClassB("String A"));
_myList.Add(new ClassB("String B"));
_myList.Add(new ClassB("String C"));
_myList.Add(new ClassB("String D"));
_myList.Add(new ClassB("String E"));
}
}
Both ClassA and ClassB are used thousands of times within the application to track performance of almost every action in the application.
I am wondering if there would be any benefit of changing these strings to static or const values.
With code like this, are multiple copies of this string stored in memory, or does .Net ensure only one copy exists regardless of how many instances of ClassA and ClassB are created?