首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

老师,这段代码为什么会提示无法实现接口成员

2013-08-21 
请教各位老师,这段代码为什么会提示无法实现接口成员?提示是这个问题:“A.Me”不实现接口成员“A.Ibankio.hav

请教各位老师,这段代码为什么会提示无法实现接口成员?
提示是这个问题:“A.Me”不实现接口成员“A.Ibankio.have”。“A.Me.have”无法实现接口成员,因为它不是公共的
请教各位大神,这是为什么呢?



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

namespace A
{
    interface Ibankio
    {
        decimal have  //已有钱数
        {
            get;
            set;
        }
        void In(decimal a);//存入钱数;
        void Out(decimal b);//支出钱数;
        /*decimal c//剩余钱数
        {
            get;
            set;

        }*/
    
    }

    class Me:Ibankio
    {
        private decimal have
        {
            get
            {
                return have;
            }
            set
            {
                if (have < 0)
                {
                    Console.WriteLine("卡内余额不足");
                }
            }
        }
        public void In(decimal a)
        {
            have += a;


            Console.WriteLine("您账户里面现有{0}元,您存了{1}元钱", have, a);
        }
        public void Out(decimal b)
        {
            if (b > have)
            {
                have -= b;
                Console.WriteLine("您账户支出{0}元,剩余{1}元!", b, have);
            }
            else
                Console.WriteLine("余额不足!");
        }
        /*public decimal c
        {
            get
            {
                return c;
            }
            set
            {
                if (have >= 0)
                {
                    value = have;
                    c = value;
                }
            }
        }*/
  }

    class Program
    {
        static void Main(string[] args)
        {
            Ibankio wo = new Me();
            wo.have = 1000;


            wo.In(10000);
            wo.Out(12000);

        }
    }
}

[解决办法]
//我做了下小修改,能跑了,不知道能不能满足需求
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Error
{
    interface Ibankio
    {
        decimal have  //已有钱数
        {
            get;
            set;
        }
        void In(decimal a);//存入钱数;
        void Out(decimal b);//支出钱数;
        /*decimal c//剩余钱数
        {
            get;
            set;
 
       }*/

    }

    class Me : Ibankio
    {
        private static decimal count;
        public decimal have
        {
            get
            {
                return count;
            }
            set
            {
                if (count < 0)


                {
                    Console.WriteLine("卡内余额不足");
                }

            }
        }
        public void In(decimal a)
        {
            count += a;
            Console.WriteLine("您账户里面现有{0}元,您存了{1}元钱", have, a);
        }
        public void Out(decimal b)
        {
            if (b < count)
            {
                count -= b;
                Console.WriteLine("您账户支出{0}元,剩余{1}元!", b, have);
            }
            else
                Console.WriteLine("余额不足!");
        }
        /*public decimal c
        {
            get
            {
                return c;
            }
            set
            {
                if (have >= 0)
                {
                    value = have;
                    c = value;


                }
            }
        }*/
    }

    class Program
    {
        static void Main(string[] args)
        {
            Ibankio wo = new Me();
            wo.have = 1000;
            wo.In(10000);
            wo.Out(12000);

        }
    }
}

热点排行