Application Output just shows nothing for a simple Hello World - c#

I'm on Elementary OS and just installed "MonoDevelop". I'm forced to use C#. However, it came up with a simple Hello World default program:
using System;
namespace HelloCsharp{
class MainClass{
public static void Main (){
Console.WriteLine ("Hello World!");
}
}
}
The problem is that my "Application Output" panel is empty.
At least it creates a new line (yet an empty line). I've selected it and thus it is shown as a "blue bar" in the following screenshot.
The checkboxes "Run on external console" and "Pause console output" are checked.
Anyone has any suggestions?
Am I right that this code normally should give me an output in this panel?

If you tick Run on external console, MonoDevelop will start your program...in an external console. By default this is /usr/bin/xterm. You can create a symlink to your preferred console application by creating a symlink to it in /usr/bin/ and naming it xterm.
If you wish to receive the output to the Application Output pad instead, untick Run on external console.

Related

How to run/test app in Debug mode (F5) and have Output window still visible during the app run (VS Express 2015)

I am new to Visual Studio Express 2015 and whole C# stuff (I come from the JAVA world).
I want to see some test string output (like checking variable values etc.) I am sending with Debug.WriteLine() during Debug mode run (F5), but the output window disappears immediately (is replaced by split dual windows). Yet when I close the running app, output window shows up back again WITH MY TEST STRING OUTPUT from Debug.WriteLine(); there - how come?
This is what I call "output window" (sorry, don't know how to call it when it has written Output on it, really...)
This is what I see when I test/run (F5) my app ("output" window is gone):
And this is what I see when I stop/close my app - "output" window is back again also with my test string I sent with Debug.WriteLine():
How can I run my app in Debug mode and also make that output window still visible during the run/test, so I could see my string output in realtime?
I need to see some test values I am sending to the output, or is there some other way how to do this in C#/Visual Studio Express 2015?
In JAVA I use NetBeans and I use Output window/CMD exactly for this, so I thought this is its equivalent. And as I see the output actually is there, it probably is, right?
Just to clarify even more: I am not creating console app that runs in CMD window, I just need to see that test output somewhere and I thought - being completely new to C# coming from JAVA - that the Output window is the place where I can see it.
Like when you C# guys need to see some test values in realtime during the app run/test, how do you do that - where your output goes? Or are you telling me there is nothing like this in Visual Studio GUI (I don't think so as I see after the app is closed my test value is present in that "output" window - the window is just not there during the app run, so...)?
I have the namespace using System.Diagnostics; in place, yet it still act as described above: in Debug mode the output window disappears, so I don't know what the string output is (have no clue how to make the window being visible still) and only comes back again once the app is closed (then there is my string output presented in the output window), with the Release mode the output window is there but no string output is displayed - it stays completely empty during the app run/test.
You just need to enable it..through the Debug->Windows->Output

How to send my notes to Output window in Visual Studio?

Have a look at the picture. No matter where i put console.writeline, nothing is showing in output. Where could be a mistake? Is something wrong with my output editor or what?
Use Debug.WriteLine to write to the Output window as you want.
See also What's the difference between Console.WriteLine() vs Debug.WriteLine()?
So you have 2 questions instead of one: your main one and the comment "How can i display console window instead of Output window?"
You can write to VS output by using Debug.WriteLine. This requires System.Diagnostics namespace.
You can also run console window alongside with your windows application. Right click the project in Solution Explorer, select Properties, change Output Type to "Console Application" like this.

Trouble with first Hello World app in Xamarin Studio

So I am starting to learn how to program and picked up a c# book and downloaded Xamarin Studio on my Mac to get started. The book I am using inevitably uses Visual Studio but I figured it would be essentially the same, but I have already come across a few issues:
When I first create a new console application, it automatically starts up with a hello world template. Is there any way to make the IDE start without this line, as I'm sure it can become somewhat of an annoyance down the road:
Console.WriteLine("Hello World!");
In other words, can I modify the template that Xamarin Studio starts up in?
When I click on Run ---> Start Debugging with the program below, I get the same result as when I run the program without debugging. In both cases, the application fully works as expected, but in my book the author mentions the screen should flash for a split second, unless you include Console.ReadKey();
Is there anything I am missing? And when I include that extra line, I get the expected result of having to push a key twice to end the program regardless of whether I run with or without debugging.
Here is the exact source code:
using System;
namespace test
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
When I first create a new console application, it automatically starts up with a hello world template. Is there any way to make the IDE start without this line, as I'm sure it can become somewhat of an annoyance down the road
Thats interesting thought but as the template itself suggests that its black console app, it should have some code which runs successfully.
When I click on Run ---> Start Debugging with the program below, I get the same result as when I run the program without debugging. In both cases, the application fully works as expected, but in my book the author mentions the screen should flash for a split second, unless you include Console.ReadKey(); Is there anything I am missing? And when I include that extra line, I get the expected result of having to push a key twice to end the program regardless of whether I run with or without debugging.
Well, this is just how Xamarin Studio works. The answer to your question lies in how Xamarin Studio is configured. By default Xamarin studio handles some things, there is an option which paused the console by default. If you want to see Console.ReadKey() in action, just right click on your project and go to options -> Run -> General -> Uncheck (Pause Console Output).
But as there is no Console built in Xamarin Studio the external Console (by default Terminal) is used you wont be able to see the flash effect.
Hope this helps. Thanks and happy coding :)

How to see output of a C# console program when running in VS?

I just wrote a clever program called helloworld. It's a C#/.NET 4.5 console app. Deep within the twisted nested mazes of logic there's use of Console.WriteLine().
When I'm running this at a command line, it runs and I see the output. I can do other commands and mess around a bit, and later scroll up to see the output again.
Now I'm in Visual Studio, tweaking the source ("Hi" is more efficient than "Hello") and testing by tapping F5. What happens is a console window pops up and immediately vanishes. I have no idea what the program printed. How can I see the output?
I don't want to modify my source at all. After searching for solutions, I find some who say to use Console.ReadKey() - but then it would suck to be using the program at the command line. There's no real reason the user should have to tap a key when the program has already done its work. Even if i go with this, there's the problem of the output disappearing when the console window closes after a key tap.
I don't want to use Debug.WriteLine() which does write to the output window in VS, but doesn't write ordinary output for the end user to see.
I have discovered ctrl-F5, which runs the program as if it had a final Console.ReadKey() line, but there's still the problem of when I tap any key, all the output vanishes along with the window. Three minutes later, I'm thinking "Oh wait, did it print 'Hello' or 'Helo'?" No way to check.
Seems like the Visual Studio IDE should somehow capture all that a freshly built program writes to its stdout or the Microsoft equivalent thereof, and show it in its "Output" panel, or some panel, for later scrutiny. Maybe it does do this, and I don't yet know the trick to it? Seems like this would be a common desire among millions of C# developers.
If you're working on a .NET Core console application (or .NET Framework via the .NET SDK) using Visual Studio 2019, the behaviour of leaving the console window open after the program has executed will now happen by default:
Specifically:
This should prevent the need to add Console.Read() calls to console apps to prevent the console window from closing immediately after the program has finished executing. The launched console window is also re-used for subsequent runs, so if you’re used to using ctrl+f5, you won’t have lots of console windows to close after you’ve launched your application a few times.
The reason it closes automaticly is because it's done running the program. If you want to see what it did, make it need a new command like hitting any key. The Console.ReadKey(); pauses it and waits for a User to hit a key to continue. Put that command after the commands of instruction you are doing and it will pause it until you hit any key.
Console.ReadKey(); // Pauses until you hit any key
You can also run your program pressing F10 (executes one line by one), with F11 (goes inside a function).
The other option you have is to set breakpoints in Visual Studion and run the program by pressing F5 - it will stop at the next breakpoint. And the breakpoints can have conditions - i.e. conditional breakpoints.
Some options are:
1. wrap #if DEBUG around Console.ReadKey()
2. run directly from an open terminal
3. create a Test project - but again you'll need Console.ReadKey() to stop it closing.

Getting started with C#, how to Debug .NET 4.0 MVC3 Project?

I am trying to self teach myself C# and wondering if anyone can help me with what seems to be a basic C# question. I created a C# file with this code, started debugging but don’t see “Hello World” anywhere.
using System;
class Hello
{
static void Main() {
Console.WriteLine("hello, world");
}
}
http://msdn.microsoft.com/en-us/library/aa664628(v=vs.71).aspx
So I guess my question is this. Where should I expect to see “Hello World”? I have checked the Console and the Browser. Is there some setup that needs to be done to properly debug C# files. I am probably missing the big picture as to how C# works. I am use to PHP where I can just do something like this...
<?php
include 'my file';
echo 'my file included';
?>
Any help would be much appreciated. Thanks.
EDIT:
Thanks everybody for all of the help. You have all helped me understand and realize a number of things about C# / .NET. After extensive troubleshooting it is evident that the problem is not a mater of the debugging working, but the fact that my C# file doesn't appear to be properly hooked/included (not sure what its called in .NET terms) to the rest of the project. Anyways I am accepting keyboardP's answer as he answered first and technically gave me all the right answers. Also thanks to dasblinkenlight who was also extra helpful.
Additional Solution:
After insight from SO users. This article helped point me in the right direction.
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3
I'm guessing it's because the command prompt window is immediately closing. You can avoid this by adding Console.ReadLine(); after your WriteLine statement. This will wait for you to press return before closing the prompt window.
Alternatively, assuming you're using Visual Studio, you can run the build without a debugger attached by pressing CTRL + F5.
Edit - Based on the extra information added that you're using ASP.NET and not a console application.
Firstly, what are you trying to achieve? If you want to output debug information, then you can Debug.WriteLine instead of Console.WriteLine
System.Diagnostics.Debug.WriteLine("Hello World");
This will output the text to the "Output" window at the bottom of Visual Studio (by default).
Edit 2 Since you just want to write random text to the page, you can use
HttpContext.Current.Response.Write("Hello World");
There are sometimes issues with Response.Write but it should be okay for what you want to do here.
Use breakpoints. Set a breakpoint at the end of your method by clicking in the "gutter" area. A red circle will appear that looks like this:
Now run your program in debug mode by clicking the button with the green triangle or pressing F5. The program will run, producing the output in the console (a separate window). Once it hits your breakpoint, you can examine the console for the output, like this:
You are reading a tutorial for Console Application, however you are trying to create a ASP.NET application. I would reccomend reading a tutorial for ASP.NET
Like many before said: it goes by too fast, so either use breakpoints, or use a Read...
You can also write to your Visual Studio output window with System.Diagnostics.Debug.Write
you need to put break point over the line which you want to debug
short cut to placing break point is ctrl D,n
then you can step over or step into the code with f10 and f11 function keys

Categories

Resources