0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C#開発

Posted at

概要

C#開発で学んだことのメモ

この記事で伝えたいこと

特になし

linuxでC#をコンパイルして実行する方法

  • Monoをインストールしてください。
    C#のコンパイラーです。

  • .csファイルを作成する。
    今回はMain関数を持つMainProc.csとエンティティクラスのAnimal.csを作成しました。

MainProc.cs
using System;
namespace HelloWorld
{
    public class MainProc
    {
        public static void Main(string[] args)
        {
            Animal animal = new Animal();
            animal.setName("ライオン");
            animal.setAge(4);
            Console.WriteLine(animal.getAge());
            Console.WriteLine(animal.getName());
        }
    }
}
Animal.cs
using System;
namespace HelloWorld
{
    public class Animal
    {
        public Animal()
        {
        }

        private string m_name;
        private int m_age;

        public string getName()
        {
            return m_name;
        }
        public int getAge()
        {
            return m_age;
        }
        public void setName(string name)
        {
            m_name = name;
        }
        public void setAge(int age)
        {
            m_age = age;
        }
    }
}
  • csファイルが格納されているディレクトリに移動する。

  • コンパイルのコマンドを実行し、exeファイルを生成する。
    mcs MainProc.cs Animal.cs

  • exeファイルを実行する。
    mono MainProc.exe

実行結果です。

4
ライオン
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?