以下の内容はhttps://white-azalea.hatenablog.jp/entry/20110130/1296387424より取得しました。


型変換を定義する

互換性のない型同士で、暗黙、明示的な型変換を定義する。

class TypeConvertionOne
{
    public string haveCode { get; set; }

    public static implicit operator TypeConvertionOne(string one)
    {
        return new TypeConvertionOne() { haveCode = one };
    }

    public static explicit operator string(TypeConvertionOne target)
    {
        return target.haveCode;
    }
}

class Program
{
    static void Main(string[] args)
    {
        TypeConvertionOne sample = "HAHAHA";

        Console.WriteLine("code : {0}", sample.haveCode);

        string reverse = (string)sample;

        Console.WriteLine("code : {0}", reverse);

        Console.ReadLine();
    }
}

情報の損失がない場合は implicit を、損失がある場合は、explicit で定義する。




以上の内容はhttps://white-azalea.hatenablog.jp/entry/20110130/1296387424より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14