print console characters faster

前端 未结 1 493
[愿得一人]
[愿得一人] 2021-01-26 23:20

I have a function that accepts a number which will convert it to a 5x7 graphic representation of digits like this:

Console.WriteLine(\" ███ \");  // byte: 0000          


        
相关标签:
1条回答
  • 2021-01-26 23:38

    I Minimized IO. Here is a version below that makes console calls only at the end.

            var stringBuilder = new StringBuilder();
            bitCounter = 0;
            foreach (bool bit in bitData)
            {                
                if (bit)
                    stringBuilder.Append("█");
                else
                    stringBuilder.Append(" ");
                bitCounter++;
                if (bitCounter > 7)
                {
                    bitCounter = 0;
                    Console.WriteLine(stringBuilder.ToString());
                    stringBuilder.Clear();
                }
            }
    
    0 讨论(0)
提交回复
热议问题