Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 2472|回复: 10
打印 上一主题 下一主题

C# 问题帮我看看哪里出错!

[复制链接]

4

主题

0

好友

476

积分

翡翠长老

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

跳转到指定楼层
1#
发表于 2009-7-6 04:57 PM |只看该作者 |倒序浏览
计算的部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

        public class Operation
        {
            private double _numberA = 0;
            private double _numberB = 0;

            public double NumberA
            {
                get { return _numberA; }
                set { _numberA = value; }

            }


            public double NumberB
            {
                get { return _numberB; }
                set { _numberB = value; }

            }

            public virtual double GetResult()
            {
                double result = 0;
                return result;
            }

        }

        class OperationAdd : Operation
        {
            public override double GetResult()
            {
                double result = 0;
                result = NumberA + NumberB;
                return result;

            }
        }

        class OperationSub : Operation
        {
            public override double GetResult()
            {
                double result = 0;
                result = NumberA - NumberB;
                return result;

            }
        }

        class OperationMul : Operation
        {
            public override double GetResult()
            {
                double result = 0;
                result = NumberA * NumberB;
                return result;
            }
        }

        class OperationDiv : Operation
        {
            public override double GetResult()
            {
                double result = 0;
                if (NumberB == 0)
                {
                    throw new Exception("Number B cannot be 0");
                }

                result = NumberA / NumberB;

                return result;
            }
        }


        public class OperationFactory
        {
            public static Operation CreateOperate(string operate)
            {
                Operation ope = null;
                switch (operate)
                {
                    case "+":
                        ope = new OperationAdd();
                        break;

                    case "-":
                        ope = new OperationSub();
                        break;

                    case "*":
                        ope = new OperationMul();
                        break;

                    case "/":
                        ope = new OperationDiv();
                        break;

                }
                return ope;

            }

        }


    }


client 部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class watever
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("please insert value A");
                string NumberA = Console.ReadLine();
                Console.Write("please insert a calculation method(+,-,*,/)");
                string operate = Console.ReadLine();
                Console.Write("please insert value B");
                string NumberB = Console.ReadLine();
                string result = "";
                result = Convert.ToString(Operation.GetResult(Convert.ToDouble(NumberA), Convert.ToDouble(NumberB), operate));
                Console.Write("the result is " + result);
                Console.ReadLine();


            }
            catch (Exception ex)
            {
                Console.Write("invalid insert asdasdasdasddddssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"+ex.Message);
            }
        }

    }
}

我看了很久看不出哪里错,请各位高手帮忙解围

error message:Error        1        No overload for method 'GetResult' takes '3' arguments        C:\Documents and Settings\Kang\Desktop\testing\ConsoleApplication1\ConsoleApplication1\Class2.cs        21        43        ConsoleApplication1

[ 本帖最后由 我是大猪头 于 2009-7-6 06:40 PM 编辑 ]




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2009-7-6 06:00 PM |只看该作者
原帖由 我是大猪头 于 2009-7-6 04:57 PM 发表
计算的部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

        public class Operation
        {
           ...



你的錯誤訊息是告訴你找不到並擁有3個參數的 GetResult 函數, 那麼你得看看是不是你的 internal 造成
雖然沒用 C#, 但是 internal 感覺像是 private 不允許 class 以外使用


  1.             public virtual double GetResult()
  2.             {
  3.                 double result = 0;
  4.                 return result;
  5.             }


  6.             internal static double GetResult(double p, double p_2, string operation)
  7.             {
  8.                 throw new NotImplementedException();
  9.             }

  10. ......

  11.                 result = Convert.ToString(Operation.GetResult(Convert.ToDouble(NumberA), Convert.ToDouble(NumberB), operate));
复制代码


回复

使用道具 举报

4

主题

0

好友

476

积分

翡翠长老

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

3#
发表于 2009-7-6 06:44 PM |只看该作者
改成public也是不可以
而且我的private number_A和number_B都是调给在同个class里面的NumberA和NumberB所以应该是没问题的吧


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

4#
发表于 2009-7-6 07:17 PM |只看该作者
原帖由 我是大猪头 于 2009-7-6 06:44 PM 发表
改成public也是不可以
而且我的private number_A和number_B都是调给在同个class里面的NumberA和NumberB所以应该是没问题的吧



你現在修改的 coding 已經去掉了 GetResult(......)  但看看你的 Main 中卻沒有修改對應的 GetResult


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

5#
发表于 2009-7-7 11:26 AM |只看该作者
  1. class OperationDiv : Operation
  2.         {
  3.             public override double [color=Red]GetResult( int  X,int y, int z)[/color]            {
  4.                 double result = 0;
  5.                 if (NumberB == 0)
  6.                 {
  7.                     throw new Exception("Number B cannot be 0");
  8.                 }

  9.                 result = NumberA / NumberB;

  10.                 return result;
  11.             }
  12.         }
复制代码



Convert.ToString(Operation.GetResult(Convert.ToDouble(NumberA), Convert.ToDouble(NumberB), operate));

你没传parameter


回复

使用道具 举报

15

主题

1

好友

168

积分

高级会员

Rank: 3Rank: 3Rank: 3

6#
发表于 2009-7-19 08:08 PM |只看该作者
  1. class OperationAdd : Operation
  2.         {
  3.             public override double [color=Red]GetResult()[/color]
  4.             {
  5.                 double result = 0;
  6.                 result = NumberA + NumberB;
  7.                 return result;

  8.             }
  9.         }

  10.         class OperationSub : Operation
  11.         {
  12.             public override double [color=Red]GetResult()[/color]
  13.             {
  14.                 double result = 0;
  15.                 result = NumberA - NumberB;
  16.                 return result;

  17.             }
  18.         }

  19.         class OperationMul : Operation
  20.         {
  21.             public override double [color=Red]GetResult()[/color]
  22.             {
  23.                 double result = 0;
  24.                 result = NumberA * NumberB;
  25.                 return result;
  26.             }
  27.         }

  28.         class OperationDiv : Operation
  29.         {
  30.             public override double [color=Red]GetResult()[/color]
  31.             {
  32.                 double result = 0;
  33.                 if (NumberB == 0)
  34.                 {
  35.                     throw new Exception("Number B cannot be 0");
  36.                 }

  37.                 result = NumberA / NumberB;

  38.                 return result;
  39.             }
  40.         }
复制代码

上面四个GETRESULT()应该改成GETRESULT(double NUMBERA, double NUMBERB)
因为:
result = Convert.ToString(Operation.GetResult(Convert.ToDouble(NumberA), Convert.ToDouble(NumberB), operate));


回复

使用道具 举报

4

主题

0

好友

476

积分

翡翠长老

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

7#
发表于 2009-8-7 03:43 PM |只看该作者
原帖由 conan0524 于 2009-7-19 08:08 PM 发表
class OperationAdd : Operation
        {
            public override double GetResult()
            {
                double result = 0;
                result = NumberA + NumberB;
         ...


感谢你的回答丫


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

8#
发表于 2009-8-14 12:08 AM |只看该作者
呵呵
有人看 大话设计模式


page 9 page 10 的 code


回复

使用道具 举报

4

主题

0

好友

476

积分

翡翠长老

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

9#
发表于 2009-8-14 02:39 PM |只看该作者
-.-
ohh,被抓到


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

10#
发表于 2009-8-14 02:57 PM |只看该作者
你有钱和前途 啦
研究了什么 快分享 出来


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-7-5 02:55 AM , Processed in 0.108753 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部