I have this code here to create a string of X spaces.
private static string GetWhiteSpaceString(int howManySpaces)
{
return new string(' ', howManySpaces);
}
How could I cache this string somehow, so its only created if the number of spaces changed for example? Is there a better way than keeping some global variable?
Thanks 🙂
I don’t think you would need to cache a
String..Nethandles it pretty well.But if you still want to proceed, why not create a of type
Dictionary<int,string>to store generated strings and look into it before returning a new one?