using System; class Trigon { static void Main() { for (double theta = 0.1; theta <= 1.0; theta = theta + 0.1) { Console.WriteLine("Синус {0:F2} равен {1:F2}\t Косинус {0:F2} равен {2:F2} Тангенс {0:F2} равен {3:F2}", theta, Math.Sin(theta), Math.Cos(theta), Math.Tan(theta)); } } } 

Hello, dear. With the help of the answers from the previous question I improved my code a little. :) Removed unnecessary words and Console.WriteLine() And no new for() ! : D I got nice columns. But again there was a problem (I know I’m tired, but I don’t have anyone else to contact. :( Do you think I’m stupid, you can write links to the right material I’ll read !!!). In the code I use \t (like tab). On {1:F2}\t everything is beautiful and normal, but when I write \t after {2:F2} distance between the value of "Cosine" and the word "Tangent" is 2 times larger (it seems, this is about). the distance and between the lines. What is the problem (why does it bother me so much? I'm a Perfectionist!: D)? You could add spaces manually, but I think that this also needs to be done erit car xD Or maybe there are other special commands to put spaces. (Example: \p5 (5 probelov.Znachenie it is possible to change))?

  • one
    Are you aware that tabulation is not the same as several spaces, and is it tied to specific positions in the line, and not relative to the character after which it goes? - teran
  • @teran Already in the know! Thank you very much. :) I took it from another code. And I found very little information (I’m talking about \ t). I opened Google, wrote a tab. On the first page it was written about 8 spaces, closed Google. : D Read more. :( - Tobi

2 answers 2

The problem with \t explained @Umed in his answer, and I will tell you how to deal with it.

If you need to insert a fixed number of spaces, you can simply use the formatting with the desired width of the output field. For example:

 Console.WriteLine("Синус {0:F2} равен {1:F2}{4,20}Косинус {0:F2} равен {2:F2} Тангенс {0:F2} равен {3:F2}", theta, Math.Sin(theta), Math.Cos(theta), Math.Tan(theta), null); 

I added a fictitious last argument, null , which is output after a sine in a field 20 characters wide.

If you use C # 6, you can write more simply:

 Console.WriteLine($"Синус {theta:F2} равен {Math.Sin(theta):F2}{' ',20}Косинус {theta:F2} равен {Math.Cos(theta):F2} Тангенс {Math.Cos(theta):F2} равен {Math.Tan(theta):F2}"); 
  • Well, with interpolation, there are more letters than without it. Each time you need to write "theta". Your answer is the best (IMHO). :) Green arrow to you. : D - Tobi
  • You used {'', 20} above, and I wrote {"", 4}, (") instead of (') in the code. What's the difference? I didn't even put a space between the quotes ... And everything works. - Tobi
  • @Tobi: There is no difference, in any case, you supplement the empty string or there is a space with other spaces up to 20 characters. That is, it turns out in the end 20 spaces. - VladD

\t aligns words by tabs, adding the missing spaces, but when words are aligned on tabs and you write \t , then add 8 (or how many tabs do you have?) space characters extra.

Example (one tab - 8 characters, one space character replaced by -| , to make it easier to count):

1234 \ t 9

will turn into:

1234 - | - | - | 9

That is, 3 characters were added and the text to the left of \t aligned to the missing tabulation.

Another example (there are already two space characters here):

123456- | - | \ t 9

Turn into:

12345- | - | - | - | - | - | - | - | - | - | 9

To the left of the \t sign there are already 8 characters and if we write \t after them, then we will add an additional tab (that is, 8 characters, since the text has already been aligned):

  • Thank you very much. And what about the spaces? There are no such commands?) If for example I want to add 1000 spaces to the text, do I have to do this manually? Or should I write additional code for such nonsense? : / - Tobi
  • @Tobi, for a thousand spaces, alas, you have to write some code yourself) - Umed