Popular Posts
DateTime package bruce.lib; import java.io.Serializable; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays... abap naming rule 命名規則 報表程式(以列表格式輸出資料分析):Yaxxxxxx或Zaxxxxxx。用應用程式區的分類字母替換a。 任何有效字元替換x。注意SAP報表程式遵守相似的命名約定:Raxxxxxx。 任何其他ABAP/4程式(培訓程式或事務程式):SAPMYxxx或SAPMZxxx... IDES 4.7 Installation 電腦名稱不能使用特殊名稱(bin/etc/var ...) 網路卡-> File and Printer Sharing for Microsoft Networks ->網路應用程式的資料輸送量最大化 安裝jdk1.4 (不升級) 設置JAVA_HOME ...
Stats
explicit, implicit and operator
public class Name
{
    /// <summary>
    /// The implicit keyword is used to declare an implicit user-defined type conversion operator.
    /// Use it to enable implicit conversions between a user-defined type and another type, 
    /// if the conversion is guaranteed not to result in a loss of data.
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static implicit operator Name(string name)
    {
        return new Name(name);
    }

    /// <summary>
    /// The explicit keyword declares a user-defined type conversion operator that must be 
    /// invoked with a cast
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static explicit operator string(Name name)
    {
        return name.Content;
    }

    /// <summary>
    /// Use the operator keyword to overload a built-in operator or to provide a user-defined 
    /// conversion in a class or struct declaration.
    /// </summary>
    /// <param name="n1"></param>
    /// <param name="n2"></param>
    /// <returns></returns>
    public static Name operator +(Name n1, Name n2)
    {
        return n1.Content + n1.Content;
    }

    string Content;

    public Name(string name)
    {
        Content = name;
    }

    public override string ToString()
    {
        return Content;
    }
}

class Program
{
    public static void Main(string[] args)
    {
        Name n1 = new Name("Bruce");
        Console.WriteLine(n1);  // output: Bruce

        Name n2 = "Bruce";      // auto cast
        Console.WriteLine(n2);  // output: Bruce

        string n3 = (string)n1; // manual cast
        Console.WriteLine(n3);  // output: Bruce

        Console.WriteLine(n1 + n2);  // output: BruceBruce
    }
}
reference: explicit, implicit, operator