Search code examples
c#xamarinxamarin-studio

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:

  1. 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?

  1. 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!");
        }
    }
}

Solution

  • 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 :)