LoginSignup
8
2

More than 5 years have passed since last update.

MacでC#のHello, World!を出力するまで

Last updated at Posted at 2016-11-27

Step

  1. Install .Net Core
  2. Install VSCode
  3. Install mono
  4. Create new project
  5. Restore project
  6. Create C# script
  7. Compile C# script
  8. Run binary

Step 1: Install .Net Core

  • 公式の通りにやるだけ
  • shellを開いていたら再起動する方がいいかもしれない

Step 2: Install VSCode

Step 3: Install mono

brew update && brew install mono

Step 4: Create new project

cd ProjectDirctory && dotnet new

Step 5: Restore project

dotnet restore

Step 6: Create C# script

cmd.cs
using System;

namespace Example
{
  class Cmd
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello, World!");
    }
  }
}

Step 7: Compile C# script

mcs cmd.cs

Step 8: Run binary

mono cmd.exe

Complete!

Appendix

複数のファイルをCompileする

hello.cs
namespace Example
{
    internal class Hello
    {
        internal string say()
        {
            return "Hello";
        }
    }
}
world.cs
namespace Example
{
    internal class World
    {
        internal string say()
        {
            return "World";
        }
    }
}
cmd.cs
using System;

namespace Example
{
  class Cmd
  {
    static void Main(string[] args)
    {
      Hello hello = new Hello();
      World world = new World();

      string h = hello.say();
      string w = world.say();
      var helloWorld = new []{ h, w };
      var msg = string.Join(", ", helloWorld);
      Console.WriteLine(msg);
    }
  }
}

mcs -out:cmd.exe -t:exe hello.cs world.cs cmd.cs
mono cmd.exe

Complete!

8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2