using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication12
{
    class Program
    {
        static void Main(string[] args)
        {
            Authenic simon = new Authenic();
            bool Done = simon.changePassword("wuengfei","MyNewPassWord");
            if (Done == true)
                Console.WriteLine("密码修改失败");
            else
                Console.WriteLine("密码修改成功");
            Console.WriteLine();
        }
    }
    class Authenic
    {
        private string Password = "wupengfei";
        public bool IsPassWordCorrect(string userPassWord)
        {
            return (Password == userPassWord) ? true : false;
        }
        public bool changePassword(string oldPassword, string newPassWord)
        {
            if (oldPassword == Password)
            {
                Password = newPassWord;
                return true;
            }
            else
                return false;
        }
    }
}
程序运行后要输出改了之后的密码是什么,应该在红色部分怎么改?

解决方案 »

  1.   


    String NewsPassword="XXXXXXXXXXXX";
    Authenic simon = new Authenic(); 
                bool Done = simon.changePassword("wuengfei",NewsPassword); 
                if (Done == true) 
                    Console.WriteLine("密码修改失败"); 
                else 
                    Console.WriteLine("密码修改成功"); 
                Console.WriteLine(NewsPassword); 
      

  2.   

    static void Main(string[] args)
            {
                Authenic simon = new Authenic();
                string oldPassWord = "wuengfei";
                string newPassWord = "MyNewPassWord";            bool Done = simon.changePassword(oldPassWord, newPassWord);
                if (Done == true)
                {
                    Console.WriteLine("密码修改失败");
                    Console.ReadKey();
                }
                else
                {
                    Console.WriteLine("密码修改成功");
                    Console.WriteLine("新密码是:" + newPassWord);
                    Console.ReadKey();
                }        }
            class Authenic
            {
                private string Password = "wupengfei";
                public bool IsPassWordCorrect(string userPassWord)
                {
                    return (Password == userPassWord) ? true : false;
                }
                public bool changePassword(string oldPassword, string newPassWord)
                {
                    if (oldPassword == Password)
                    {
                        Password = newPassWord;
                        return true;
                    }
                    else
                        return false;
                }
            }
      

  3.   

    Authenic simon = new Authenic(); 
    bool Done = simon.changePassword("wuengfei",newPassWord); 
         if (Done == true) 
            Console.WriteLine("密码修改成功"+newPassWord); 
         else 
              Console.WriteLine("密码修改失败"); 
        Console.WriteLine(); 
      

  4.   

    Authenic simon = new Authenic(); 
    string newPassWord="";
    bool Done = simon.changePassword("wuengfei",newPassWord); 
      

  5.   

    bool Done = simon.changePassword("wuengfei","MyNewPassWord"); 
    把后面的"MyNewPassWord" 以字符串形式传入,
    bool Done = simon.changePassword("wuengfei",newPassWord); 
    这样输出newPassWord就可以了
      

  6.   

     
      // 改成这样就行
       class Program
        {        
            class Authenic 
            { 
                private string Password = "123"; 
                public bool IsPassWordCorrect(string userPassWord) 
                { 
                    return (Password == userPassWord) ? true : false; 
                } 
                public bool changePassword(string oldPassword,ref string newPassWord) 
                {
                    if (oldPassword == Password)
                    {
                        Password = newPassWord;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                } 
            } 
            static void Main(string[] args)
            {
                Program.Authenic simon = new Authenic();            // Authenic simon = new Authenic();
                string old_Password = Console.ReadLine();
                string new_Password = Console.ReadLine();
                bool Done = simon.changePassword(old_Password,ref new_Password);
                if (Done == true)
                {
                    Console.WriteLine("密码修改成功");
                    Console.WriteLine("The New PassWord is " + new_Password.ToString());
                }
                else
                {
                    Console.WriteLine("密码修改失败");
                }
            }
        }