<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 如何:使用運算符重載創建復數類(C# 編程指南) 本示例展示如何使用運算符重載創建定義復數加法的復數類 Complex。本程序使用 **ToString** 方法的重載顯示數字的虛部和實部以及加法結果。 ``` public struct Complex { public int real; public int imaginary; // Constructor. public Complex(int real, int imaginary) { this.real = real; this.imaginary = imaginary; } // Specify which operator to overload (+), // the types that can be added (two Complex objects), // and the return type (Complex). public static Complex operator +(Complex c1, Complex c2) { return new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary); } // Override the ToString() method to display a complex number // in the traditional format: public override string ToString() { return (System.String.Format("{0} + {1}i", real, imaginary)); } } class TestComplex { static void Main() { Complex num1 = new Complex(2, 3); Complex num2 = new Complex(3, 4); // Add two Complex objects by using the overloaded + operator. Complex sum = num1 + num2; // Print the numbers and the sum by using the overridden // ToString method. System.Console.WriteLine("First complex number: {0}", num1); System.Console.WriteLine("Second complex number: {0}", num2); System.Console.WriteLine("The sum of the two numbers: {0}", sum); // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } } /* Output: First complex number: 2 + 3i Second complex number: 3 + 4i The sum of the two numbers: 5 + 7i */ ``` ## 請參閱 [C# 編程指南](https://msdn.microsoft.com/zh-cn/library/67ef8sbd.aspx) [C# 運算符](https://msdn.microsoft.com/zh-cn/library/6a71f45d.aspx) [運算符(C# 參考)](https://msdn.microsoft.com/zh-cn/library/s53ehcz3.aspx) [Why are overloaded operators always static in C#?(在 C# 中,為什么重載的運算符始終是靜態的?)](http://go.microsoft.com/fwlink/?LinkId=112383)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看