If you want to post a snippet of code to Microsoft Teams go to the Conversations tab and then select the Format text icon as shown above.
From this expanded dialog box select the Code icon as shown.
This should display a new dialog like shown above.
If you select the options in the top right you will see a huge range of code selections displayed as shown.
In the above case, I have select PowerShell and you can see that it formats and colours the code snippet for me automatically making it much easier to read.
You can now post the result and that will be added to the Teams Conversations as shown above. You will see that it even automatically add line numbers, which is very handy.
Thus, if you are going to post code into Microsoft Teams Conversations, make sure you do it via the Format Text option so that it is formatted in a way that makes it more readable.