Hello,
I am trying to format a string in C# but am having trouble trying to set the width. Is there a way to use a variable int as the width instead of having to declare a static width?
here is my code now...
for (int i = 0; i < max; i++)
{
string newString = String.Format("{0,15:D}{1,15:D}", i+1, squares[i]);
System.Console.WriteLine(newString);
}
what I would like to do is something like this (where width is set elsewhere)
int width = 15;
for (int i = 0; i < max; i++)
{
string newString = String.Format("{0,width:D}{1,width:D}", i+1, squares[i]);
System.Console.WriteLine(newString);
}
Is this possible?