代码如下:
using System.Collections.Generic;
using System.Text;
using Wrox.ProCSharp;
using Wrox.ProCSharp.VenusBank;
using Wrox.ProCSharp.JupiterBank;namespace Wrox.ProCSharp
{
    public interface lBankAccount
    {
        void PayIn(decimal amount);
        bool WithDraw(decimal amount);
        decimal Balance
        {
            get;
        }
    }
}
namespace Wrox.ProCSharp.VenusBank
{
    public class SaverAccount : lBankAccount
    {
        private decimal banlance;         public void PayIn(decimal amount)
        {
            banlance += amount;
        }         public bool Withdraw(decimal amount)
        {
            if(banlance>=amount)
            {
                banlance -= amount ;
                return true;
            }            Console.WriteLine("withDraw attempt failed");
            return false;
        }
         
         public decimal Banlance
        {
            get
            {
                return banlance;
            }
        }        public override string  ToString()
        {
          return string.Format("Verus Bank Saver:Balance={0,6:C}",banlance);
        }
    }       
}
namespace Wrox.ProCSharp.JupiterBank
{
    public class GoldAccount : lBankAccount 
    {    }
}
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            lBankAccount venusAccount = new SaverAccount();
            lBankAccount jupiterAccount = new GoldAccount();
            venusAccount.PayIn(200);
            venusAccount.WithDraw(100);
            Console.WriteLine(venusAccount.ToString());
            jupiterAccount.PayIn(500);
            jupiterAccount.WithDraw(600);
            jupiterAccount.WithDraw(100);
            Console.WriteLine(jupiterAccount.ToString());
        }
    }
}
出错:
错误 1 “Wrox.ProCSharp.VenusBank.SaverAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.WithDraw(decimal)” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 24 18 ConsoleApplication1
错误 2 “Wrox.ProCSharp.VenusBank.SaverAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.Balance” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 24 18 ConsoleApplication1
错误 3 “Wrox.ProCSharp.JupiterBank.GoldAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.PayIn(decimal)” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 63 18 ConsoleApplication1
错误 4 “Wrox.ProCSharp.JupiterBank.GoldAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.WithDraw(decimal)” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 63 18 ConsoleApplication1
错误 5 “Wrox.ProCSharp.JupiterBank.GoldAccount”不会实现接口成员“Wrox.ProCSharp.lBankAccount.Balance” d:\wody\Projects\form\ConsoleApplication1\ConsoleApplication1\Program.cs 63 18 ConsoleApplication1

解决方案 »

  1.   

    using System.Collections.Generic; 
    using System.Text; 
    using Wrox.ProCSharp; 
    using Wrox.ProCSharp.VenusBank; 
    using Wrox.ProCSharp.JupiterBank; 这里不是全部引用了吗?我是初学者,可以说详细一点吗?
      

  2.   

    晕,你一个类文件里这么多引用
    最好分开。
    interface是一个文件,
    实现类是一个文件。
    using System.Collections.Generic; 
    using System.Text; 
    using Wrox.ProCSharp; 
    using Wrox.ProCSharp.VenusBank; 
    using Wrox.ProCSharp.JupiterBank; namespace Wrox.ProCSharp 

        public interface lBankAccount 
        { 
            void PayIn(decimal amount); 
            bool WithDraw(decimal amount); 
            decimal Balance 
            { 
                get; 
            } 
        } 
    } using System.Collections.Generic; 
    using System.Text; 
    using Wrox.ProCSharp; 
    using Wrox.ProCSharp.VenusBank; 
    using Wrox.ProCSharp.JupiterBank; namespace ConsoleApplication1 

        class Program 
        { 
            static void Main(string[] args) 
            { 
                lBankAccount venusAccount = new SaverAccount(); 
                lBankAccount jupiterAccount = new GoldAccount(); 
                venusAccount.PayIn(200); 
                venusAccount.WithDraw(100); 
                Console.WriteLine(venusAccount.ToString()); 
                jupiterAccount.PayIn(500); 
                jupiterAccount.WithDraw(600); 
                jupiterAccount.WithDraw(100); 
                Console.WriteLine(jupiterAccount.ToString()); 
            } 
        } 

      

  3.   

    我把所有的代码分成了四个文件
    namespace Wrox.ProCSharp 

        public interface lBankAccount 
        { 
            void PayIn(decimal amount); 
            bool WithDraw(decimal amount); 
            decimal Balance 
            { 
                get; 
            } 
        } 

    这里一个文件namespace Wrox.ProCSharp.VenusBank 

        public class SaverAccount : lBankAccount 
        { 
            private decimal banlance;          public void PayIn(decimal amount) 
            { 
                banlance += amount; 
            }          public bool Withdraw(decimal amount) 
            { 
                if(banlance> =amount) 
                { 
                    banlance -= amount ; 
                    return true; 
                }             Console.WriteLine("withDraw attempt failed"); 
                return false; 
            } 
              
             public decimal Banlance 
            { 
                get 
                { 
                    return banlance; 
                } 
            }         public override string  ToString() 
            { 
              return string.Format("Verus Bank Saver:Balance={0,6:C}",banlance); 
            } 
        }        

    这里一个文件
    namespace Wrox.ProCSharp.JupiterBank 

        public class GoldAccount : lBankAccount  
        {     } 

    这里一个namespace ConsoleApplication1 

        class Program 
        { 
            static void Main(string[] args) 
            { 
                lBankAccount venusAccount = new SaverAccount(); 
                lBankAccount jupiterAccount = new GoldAccount(); 
                venusAccount.PayIn(200); 
                venusAccount.WithDraw(100); 
                Console.WriteLine(venusAccount.ToString()); 
                jupiterAccount.PayIn(500); 
                jupiterAccount.WithDraw(600); 
                jupiterAccount.WithDraw(100); 
                Console.WriteLine(jupiterAccount.ToString()); 
            } 
        } 
    } 这里一个。
    在文件的前面全部引用了命名空间。但问题依旧
      

  4.   

    using System.Collections.Generic; 
    using System.Text; 
    using Wrox.ProCSharp; 
    using Wrox.ProCSharp.VenusBank; 
    using Wrox.ProCSharp.JupiterBank; namespace Wrox.ProCSharp 

        public interface lBankAccount 
        { 
            void PayIn(decimal amount); 
            bool WithDraw(decimal amount); 
            decimal Balance 
            { 
                get; 
            } 
        } 

    namespace Wrox.ProCSharp.VenusBank 

        public class SaverAccount : lBankAccount 
        { 
            private decimal banlance;          public void PayIn(decimal amount) 
            { 
                banlance += amount; 
            }          public bool Withdraw(decimal amount) 
            { 
                if(banlance> =amount) 
                { 
                    banlance -= amount ; 
                    return true; 
                }             Console.WriteLine("withDraw attempt failed"); 
                return false; 
            } 
              
             public decimal Banlance 
            { 
                get 
                { 
                    return banlance; 
                } 
            }         public override string  ToString() 
            { 
              return string.Format("Verus Bank Saver:Balance={0,6:C}",banlance); 
            } 
        }        

    namespace Wrox.ProCSharp.JupiterBank 

        public class GoldAccount : lBankAccount  
        { 
    这里没有实现lBankAccount  接口
     private decimal banlance;          public void PayIn(decimal amount) 
            { 
                banlance += amount; 
            }          public bool Withdraw(decimal amount) 
            { 
                if(banlance> =amount) 
                { 
                    banlance -= amount ; 
                    return true; 
                }             Console.WriteLine("withDraw attempt failed"); 
                return false; 
            } 
              
             public decimal Banlance 
            { 
                get 
                { 
                    return banlance; 
                } 
            }         public override string  ToString() 
            { 
              return string.Format("Verus Bank Saver:Balance={0,6:C}",banlance); 
            } 

        } 

    namespace ConsoleApplication1 

        class Program 
        { 
            static void Main(string[] args) 
            { 
                lBankAccount venusAccount = new SaverAccount(); 
                lBankAccount jupiterAccount = new GoldAccount(); 
                venusAccount.PayIn(200); 
                venusAccount.WithDraw(100); 
                Console.WriteLine(venusAccount.ToString()); 
                jupiterAccount.PayIn(500); 
                jupiterAccount.WithDraw(600); 
                jupiterAccount.WithDraw(100); 
                Console.WriteLine(jupiterAccount.ToString()); 
            } 
        } 
      

  5.   

    这是个明显的低级错误!!!!!!!!!!!!!!!!!!!要求实现的那两个东西
    bool WithDraw(decimal amount);  
    decimal Balance
    {
     get;
    }一个是被你写成了Withdraw   (应该是WithDraw)
    另一个是被你写成了Banlance (应该是Balance)还有
    你根本就没有导入 System 命名空间,就写上了Console.WriteLine
      

  6.   

    真的好眼力,不说我还没注意到没引入System命名空间呢..
      

  7.   

    很明白啊
    没有实现接口中的成员啊
    是你的大小写
    在接口中是大写
    bool WithDraw(decimal amount); 
    可是到了实现的类中就变成了小写了
    public bool Withdraw(decimal amount) 
      

  8.   


        public class SaverAccount : IBankAccount 
        { 
            void IBankAccount.PayIn(decimal amount)
            //必须写明是实现哪个接口的方法
            { 
                //省略
            }         bool IBankAccount.Withdraw(decimal amount) 
            { 
                //省略
            } 
              
            decimal IBankAccount.Banlance 
            { 
                //省略
            } 
        }