none
Hello World not working RRS feed

  • Question

  • Hello world!

    I'm trying to teach myself c# using the Sams learn in 24 hours book, but as much as it pains me to admit it, I can't seem to get past the first activity.

    I'm trying to run a form with a simple "Hello world" text line, but when I debug the code, the form loads up blank for some reason.

    Here's my code: 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace ConsoleHelloWorld
    {
        class Program
        {
    
            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
    
                Console.WriteLine("Hello, world");
            }
        }
    }
    

    All the code was loaded in by default except for the one line I've written:

    Console.WriteLine("Hello, world");

    Thanks for your help in advance.

    Saturday, November 10, 2018 12:22 PM

Answers

  • Hello world!

    I'm trying to teach myself c# using the Sams learn in 24 hours book, but as much as it pains me to admit it, I can't seem to get past the first activity.

    I'm trying to run a form with a simple "Hello world" text line, but when I debug the code, the form loads up blank for some reason.

    Here's my code: 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace ConsoleHelloWorld
    {
        class Program
        {
    
            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
    
                Console.WriteLine("Hello, world");
            }
        }
    }

    All the code was loaded in by default except for the one line I've written:

    Console.WriteLine("Hello, world");

    Thanks for your help in advance.

    It appears that you have created a Windows Form project.  The application created for this type of project will not display a console -- "Hello, world" will not be seen.

    Start over and create a new project for a C# Console project. 

    • Marked as answer by ClumsyOrcaa Saturday, November 10, 2018 12:44 PM
    Saturday, November 10, 2018 12:34 PM

All replies

  • Hello world!

    I'm trying to teach myself c# using the Sams learn in 24 hours book, but as much as it pains me to admit it, I can't seem to get past the first activity.

    I'm trying to run a form with a simple "Hello world" text line, but when I debug the code, the form loads up blank for some reason.

    Here's my code: 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace ConsoleHelloWorld
    {
        class Program
        {
    
            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
    
                Console.WriteLine("Hello, world");
            }
        }
    }

    All the code was loaded in by default except for the one line I've written:

    Console.WriteLine("Hello, world");

    Thanks for your help in advance.

    It appears that you have created a Windows Form project.  The application created for this type of project will not display a console -- "Hello, world" will not be seen.

    Start over and create a new project for a C# Console project. 

    • Marked as answer by ClumsyOrcaa Saturday, November 10, 2018 12:44 PM
    Saturday, November 10, 2018 12:34 PM
  • Sorted.  Thanks for your help!
    Saturday, November 10, 2018 12:45 PM