现在的位置: 首页 > 综合 > 正文

C# 模拟一个手机充值的过程,还不完美。

2012年01月31日 ⁄ 综合 ⁄ 共 1271字 ⁄ 字号 评论关闭

using System;

using System.Collections.Generic;

using System.Text;

 

namespace AddMoney

{

    /// <summary>

    /// 此示例是模拟手机冲值过程

    /// </summary>

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("欢迎使用全业务充值服务!");

            bool success = AddMoney();   // 充值操作

            if (success)

            {

                Console.WriteLine("充值成功!");

            }

            else

            {

                Console.WriteLine("充值失败!");

            }

 

            Console.ReadLine();

        }

 

        // 模拟充值过程

        private static bool AddMoney()

        {

            string input;  // 用户的输入

            string phoneNumber;  // 手机号码

            int position;  // 最后一个#的位置

 

            Console.WriteLine("请输入您的充值卡号、密码和要充值的手机号码,以#分隔:");

            input = Console.ReadLine();

            position = input.LastIndexOf("#");

            if (position > 0)

            {

                phoneNumber = input.Substring(position+1);

                Console.WriteLine("您要充值的手机号码是:{0}",phoneNumber);

                Console.WriteLine("确认充值请按1,取消请按其他键。");

                if (Console.ReadLine() == "1")

                {

                    return true;

                }

                else

                {

                    return false;

                }

            }

            else

            {

                return false;

            }

        }

    }

}

 

抱歉!评论已关闭.