.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
我的印度软件老师,给的 几个C# PROGRAMS

作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站

using System;

namespace Wrox.ProCSharp.OOProg     //The first program
{
   class MainEntryPoint
   {
      static void Main()
      {
         Authenticator myAccess = new Authenticator();
         bool done;
         done = myAccess.ChangePassword("", "MyNewPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");
         done = myAccess.ChangePassword("", "AnotherPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");

         if (myAccess.IsPasswordCorrect("WhatPassword"))
            Console.WriteLine("Verified myAccess\' password");
         else
            Console.WriteLine("Failed to verify myAccess\' password");
      }

   }

   public class Authenticator
   {
      // implementation as shown earlier

      private string password = "";
  
      public bool IsPasswordCorrect(string tryPassword)
      {
         return (tryPassword == password) ? true : false;
      }

      public bool ChangePassword(string oldPassword, string newPassword)
      {
         if (oldPassword == password)
         {
            password = newPassword;
            return true;
         }
         else
            return false;
      }
   }
}

using System;

namespace Wrox.ProCSharp.OOProg    //The Second program
{
   class MainEntryPoint
   {
      static void Main()
      {
         Authenticator myAccess = new Authenticator();
         bool done;
         done = myAccess.ChangePassword("", "MyNewPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");
         done = myAccess.ChangePassword("", "AnotherPassword");
         if (done == true)
            Console.WriteLine("Password for myAccess changed");
         else
            Console.WriteLine("Failed to change password for myAccess");

         if (myAccess.IsPasswordCorrect("WhatPassword"))
            Console.WriteLine("Verified myAccess\' password");
         else
            Console.WriteLine("Failed to verify myAccess\' password");
      }

   }

   public class Authenticator
   {
      // implementation as shown earlier

      private string password = "";
  
      public bool IsPasswordCorrect(string tryPassword)
      {
         return (tryPassword == password) ? true : false;
      }

      public bool ChangePassword(string oldPassword, string newPassword)
      {
         if (oldPassword == password)
         {
            password = newPassword;
            return true;
         }
         else
            return false;
      }
   }
}

namespace Wrox.ProCSharp.OOProg
{
   using System;
   public enum TypeOfCall
   {
      CallToCellPhone, CallToLandline
   }

   public class Customer
   {
      private string name;
      private decimal balance;
      public string Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }

      public decimal Balance
      {
         get
         {
            return balance;
         }
      }
      public void RecordPayment(decimal amountPaid)
      {
         balance -= amountPaid;
      }
      public void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
               balance += (0.30M * nMinutes);
               break;
            default:
               break;
         }
      }
   }
   public class MainEntryPoint
   {
      public static void Main()
      {
         Customer arabel = new Customer();
         arabel.Name = "Arabel Jones";
         Customer mrJones = new Customer();
         mrJones.Name = "Ben Jones";
         arabel.RecordCall(TypeOfCall.CallToLandline, 20);
         arabel.RecordCall(TypeOfCall.CallToCellPhone, 5);
         mrJones.RecordCall(TypeOfCall.CallToLandline, 10);
         Console.WriteLine("{0,-20} owes ${1:F2}", arabel.Name, arabel.Balance);
         Console.WriteLine("{0,-20} owes ${1:F2}", mrJones.Name, mrJones.Balance);
      }
   }
}

namespace Wrox.ProCSharp.OOProg
{
   using System;
   public enum TypeOfCall
   {
      CallToCellPhone, CallToLandline
   }

   public class Customer
   {
      private string name;
      protected decimal balance;
      public string GetFunnyString()
      {
         return "Plain ordinary customer. Kaark!";
      }
      public string Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }

      public decimal Balance
      {
         get
         {
            return balance;
         }
      }
      public void RecordPayment(decimal amountPaid)
      {
         balance -= amountPaid;
      }
      public virtual void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
               balance += (0.30M * nMinutes);
               break;
            default:
               break;
         }
      }
   }
   public class Nevermore60Customer : Customer
   {
      private uint highCostMinutesUsed;
      public new string GetFunnyString()
      {
         return "Nevermore60. Nevermore!";
      }
      public override void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
         uint highCostMinutes, lowCostMinutes;
         uint highCostMinutesToGo =
            (highCostMinutesUsed < 60) ? 60 - highCostMinutesUsed : 0;
         if (nMinutes > highCostMinutesToGo)
         {
            highCostMinutes = highCostMinutesToGo;
            lowCostMinutes = nMinutes - highCostMinutes;
         }
         else
         {
            highCostMinutes = nMinutes;
            lowCostMinutes = 0;
         }
         highCostMinutesUsed += highCostMinutes;
         balance += (0.50M * highCostMinutes + 0.20M *
            lowCostMinutes);
         break;
            default:
               break;
         }
      }
   }
   public class MainEntryPoint
   {
      public static void Main()
      {
         Customer cust1;
         Nevermore60Customer cust2;
         cust1 = new Customer();
         Console.WriteLine("Customer referencing Customer: "
            + cust1.GetFunnyString());
         cust1 = new Nevermore60Customer();
         Console.WriteLine("Customer referencing Nevermore60Customer: "
            + cust1.GetFunnyString());
         cust2 = new Nevermore60Customer();
         Console.WriteLine("Nevermore60Customer referencing: "
            + cust2.GetFunnyString());  
      }
   }
}




相关文章

相关软件