| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:重载的问题
只看楼主 加入收藏
xyq701830
Rank: 1
来 自:浙江
等 级:新手上路
威 望:2
帖 子:263
专家分:0
注 册:2008-6-24
收藏
 问题点数:0 回复次数:0 
重载的问题
using System;
using System.Collections.Generic;
using System.Text;

namespace _80714chongzai
{
    class Program
    {
        public class Complex
        {
            public int real;
            public int imaginary;

            public Complex(int real , int imaginary)
            {
                this.real = real;
                this.imaginary = imaginary;
            }

            public static Complex operator +(Complex x1,Complex x2)
            {
                return new Complex(x1.real + x2.real, x1.imaginary + x2.imaginary);
            }

            public override string ToString()
            {
                return (String.Format("{0}+{1}i", real, imaginary));
            }

            static void Main(string[] args)
            {
                Complex num1 = new Complex(2, 3);
                Complex num2 = new Complex(3, 4);
                Complex sum = num1 + num2;
                Console.WriteLine("1:\t{0}", num1);
                Console.WriteLine("2:\t{0}", num2);
                Console.WriteLine("1+2:\t{0}", num1 + num2);
            }
        }
    }
}



这里public static Complex operator +(Complex x1,Complex x2)中的operator +  是什么用呢
搜索更多相关主题的帖子: imaginary 
2008-07-15 22:29
快速回复:重载的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044464 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved