C# オーバーライド

using System;

//基本クラス
class Music
{
public virtual void BaseInfo()
{
Console.WriteLine(“Music”);
}
}

//派生クラス
class Song : Music
{
public override void BaseInfo()
{
Console.WriteLine(“Song”);
}
}

//派生クラス
class Music2 : Music
{
new public void BaseInfo()
{
Console.WriteLine(“Music2”);
}
}

class MainClass
{
static void Main()
{
Song s = new Song();
s.BaseInfo();

    Music2 m2 = new Music2();
    m2.BaseInfo();

    Music m = new Music();
    m.BaseInfo();
}

}

C# 変数

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test3 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int a;

    float b;

    string c;

    bool d;

    a = 1;
    b = 0.01f;
    c = "勇者の登場";
    d = true;

    //コンソールに表示
    Debug.Log(a);
    Debug.Log(b);
    Debug.Log(c);
    Debug.Log(d);
}

}

C# Unity Test

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class TestScript : MonoBehaviour

{

    // Start is called before the first frame update

    void Start()

    {

       string a;

       string b;

       a = “真理”;

       b = “りんご”;

       Debug.Log(a + “は” + b + “が好きです。”);

       a = “マリアンヌ”;

       b = “メロン”;

       Debug.Log(a + “は” + b + “好きです。”);

    }

    // Update is called once per frame

    void Update()

    {

        //Debug.Log(“連続表示”);

    }

}

C# 名前付きパラメーター

using System;

namespace TestNamespace
{
internal class HP
{
public int CalcAdd2(int a, int b, int c)
{
return a + b + c;
}
}

class Program
{
    static void Main(string[] args)
    {
        HP test = new HP();

        int a = test.CalcAdd2(a: 3, b: 4, c: 2);

        int b = test.CalcAdd2(a: 3, b: 1, c: 2);

        Console.WriteLine(a);
        Console.WriteLine(b);
    }
}

}