How do I view the "output" of my code in Visual Studio permanently like with .NET?
Complete noob here, sorry if this is stupid, I did google first but couldn't find what I was looking for, probably because I can't explain it well enough so bear with me as I try to do that now:
- I'm currently following the "Hello World" intro to C# course on microsoft.learn
- on the .Net editor I type in my code, press run, and in the output window it displays the code I just put down
- When I tried to do the same thing in visual studio, the output showed up in a tiny window for a split second then disappeared, as the code became more "complicated" the window didn't show up at all even though it said there were no errors
- Mac monterey 12.6.1
Appreciate any help, thanks.
About this post
- Posted
- Archived
- Score
- 2 · 67% up
- Kind
- Text
- ID
- 14rw654
8 comments
try adding Console.ReadLine() at the end
To add onto this, by adding Console.ReadLine(), the program waits for the user input, and keeps it running.
The application will exit when there's nothing else to "do".
Just do it by slow and small steps
That doesn't say anything
Put a breakpoint at the end.
I see you are on a Mac but for Visual Studio 2022 on windows it now keeps that window open by default. If Mac doesn't have the option, then adding a break point at the end will help.
Here is the setting (unchecked)
https://preview.redd.it/gli4u7jd1dab1.png?width=802&format=png&auto=webp&v=enabled&s=9b1b7d78121e6977fe1c92ac2e9169ba80bf2d61
Try this https://marketplace.visualstudio.com/items?itemName=NesviatypaskhaOleksii.VsConsoleOutput
The .Net editor sounds like it uses the .Net Framework, which can display things. The "hello world" programm on .Net tells the framework to display "hello world".
If you are using Visual Studio (alone), you don't automatically use any Framework to display anything. That is likely why something that worked in the .Net editor to display text doesn't work in VS.
That means the programm opens in a console, but has nothing to display, so it does everything it is supposed to do but closes right after. What the other comment said should tell your programm to display whats in the brackets and add a linebreak, which in turn prompts it to stay (as a console) and not instantly close.
If you are also using the .Net Framework in Visual Studio, it might just be that VS doesn't tell .Net to start properly. In any case, a look on the code would be helpful here.