| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1873 人关注过本帖
标题:大家帮我解释一个动态数组错误的问题
只看楼主 加入收藏
s114747867
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-11-29
收藏
 问题点数:0 回复次数:11 
大家帮我解释一个动态数组错误的问题
大家帮我看看我的这个程序动态数组怎么没用     

这是个停车场的的添加

 bool IfHuoche(ref HuoChe hc)
        {
            bool ifrigth = false;
            bool ifContinue = true;
            
            while (ifContinue)
            {
                Console.WriteLine("请输入车的排量,输入n退出本次添加!");
              string input=Console.ReadLine();
              
              if (input.ToLower()=="n")
              {
                  ifContinue = false;
              }
              else if (int.Parse(input) >= 10 && int.Parse(input) <= 100)
              {
                  hc.Pailiang = Int32.Parse(input);
                  Console.WriteLine("请输入您的车牌号!");
                  string carname = Console.ReadLine();
                  bool name = Worke.Juge10(carname);
                  if (name)
                  {
                      hc.Carnumber = carname;
                      Console.WriteLine("请输入您的姓名!");
                      hc.Ownername = Console.ReadLine();
                      if (carinfor == null)
                      {
                          carinfor = new ArrayList();

                      }
                      Car c = (Car)hc;
                      carinfor.Add(c);
                      ifrigth = true;
                      continue;
                  }
                  else
                  {
                      Console.WriteLine("您的必须是位的号码!");
                  }
              }
              else
              {
                  Console.WriteLine("您的排量超标,不能进!");
              }
               
                }
        
            return ifrigth;
        }

我在线等   大家帮我看看   我都迷茫半天了
其中动态数组是    ArrayList carinfor
搜索更多相关主题的帖子: 动态 bool input ifContinue false 
2008-07-22 13:43
yangyaming6208
Rank: 1
来 自:安徽师范大学
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-7-21
收藏
得分:0 
ArrayList carinfor = new ArrayList();
这么定义吧?
2008-07-22 13:50
s114747867
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-11-29
收藏
得分:0 
这个没问题的   我先定义没实例化
2008-07-22 13:52
itwalker
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-7-11
收藏
得分:0 
if (carinfor == null)
                      {
                          carinfor = new ArrayList();

                      }
以上代码不应该这样写.变量在类的构造中初始化.

C#交流群:24752536.目前120人.欢迎加入
UNIX/LUNIX/MACOS 群:12723740刚建立
2008-07-22 13:54
s114747867
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-11-29
收藏
得分:0 
Car 是我做的一个类    用来存放车辆信息的    比如  pailiang  .....   hc是Car的实例化对象
2008-07-22 13:54
yangyaming6208
Rank: 1
来 自:安徽师范大学
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-7-21
收藏
得分:0 
源代码发我看看!
2008-07-22 13:54
s114747867
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-11-29
收藏
得分:0 
源代码400多行   要看我就发
2008-07-22 13:55
s114747867
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-11-29
收藏
得分:0 
using System;
using System.Collections;
namespace StopStation
{

    /// <summary>
    /// 检验
    /// </summary>
    class CheckInfor
    {
       public static bool ifPaiLiang(int pailiang)
        {
            if (pailiang<10 ||pailiang>100)
            {
                return false;
            }
            else
            {
                return true;
            }
               
        }
        public static bool ifSudu(int sudu)
        {
            if (sudu < 10 || sudu > 100)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool ifzhuangxiou(string zhuanxiu)
        {
            if (zhuanxiu.Equals("差"))
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
   
    enum CarClass
    {
        货车,轿车,面包车
    }
    enum Station
    {
        已出,未出
    }
    class Program
    {
        
        static void Main()
        {
            Worke wor = new Worke();
            bool isgoon = true;
            Console.WriteLine("请输入要选择的种类:1进车;2出车;'N'表示退出");
            string input=Console.ReadLine();
            input = input.ToLower();
            while (isgoon)
            {
                switch (input)
                {
                    case "1":
                        wor.AddCar();
                       
                        break;
                    case "2":
                        wor.DellCar();
                        break;
                    case "3":
                        break;
                    default:
                        break;
                }
            }
            
         
        }

    }
    class Worke
    {
        ArrayList carinfor;
      
        public ArrayList Carinfor
        {
            get { return carinfor; }
            set { carinfor = value; }
        }
        public  void ShowInfor()
        {
            if (carinfor==null)
            {
                Console.WriteLine("现在停车场还没有停过车!");
            }
            else
            {
                Console.WriteLine("车类   车号    车主名   状态  排量  速度   装修");
                foreach (object o in carinfor)
                {
                    try
                    {
                        Car c = (Car)o;
                        if (c.Cc == CarClass.货车)
                        {
                            HuoChe hc = (HuoChe)c;
                            Console.WriteLine(hc.Cc.ToString() + "   " + hc.Carnumber + "  " + hc.Ownername + "  " + hc.Sta.ToString() + "  " + hc.Pailiang.ToString());
                        }
                        else if (c.Cc == CarClass.轿车)
                        {
                            JiaoChe jc = (JiaoChe)c;
                            Console.WriteLine(jc.Cc.ToString() + "   " + jc.Carnumber + "  " + jc.Ownername + "  " + jc.Sta.ToString() + "  " +jc.Shudu.ToString());
                        }
                        else if (c.Cc == CarClass.面包车)
                        {
                            MianBaoChe mb = (MianBaoChe)c;
                            Console.WriteLine(mb.Cc.ToString() + "   " +mb.Carnumber + "  " + mb.Ownername + "  " + mb.Sta.ToString() + "  " + mb.Zhuanxiu.ToString());
                        }
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    
                }
            }

        }
        public void AddCar()
        {

            bool ifContinue = true ;
            string input;
            while (ifContinue)
            {
                Console.WriteLine("请出入您想添加车的种类,种类有,货车,轿车,面包车三种,按n退出本次操作");
                input = Console.ReadLine();
                input = input.ToLower();
                switch (input)
                {
                    case "货车":
                        HuoChe hc = new HuoChe();
                        hc.Cc = CarClass.货车;
                        bool add=IfHuoche(ref hc);
                        if (add)
                            Console.WriteLine("添加完成!");
                        else Console.WriteLine("添加不成功!");
                        break;
                    case "轿车":
                        JiaoChe jc=new JiaoChe();
                        jc.Cc=CarClass.轿车;
                        ifjiaoche(ref jc);
                        break;
                    case "面包车":
                        MianBaoChe mb = new MianBaoChe();
                        mb.Cc = CarClass.面包车;
                        ifmianbao(ref mb);
                        break;
                    case "n":
                        ifContinue = false;
                        break;
                    default:
                        Console.WriteLine("您的输入又误!您的输入是:"+input+'\n');
                        break;
                }
            }
        }
      
        public void DellCar()
        {
            Console.WriteLine("--------------");
            if (carinfor == null)
            {
                Console.WriteLine("停车场现在没有车");
            }
            else
            {
                Console.WriteLine("请输入要出车辆的车牌号");
                string input = Console.ReadLine();
                bool rigthput = Worke.Juge10(input);
                if (rigthput)
                {
                    foreach (object o in carinfor)
                    {
                        Car dellCar = (Car)o;
                        if (dellCar.Carnumber == input)
                        {
                            carinfor.Remove(dellCar.Carnumber);
                            Console.WriteLine("删除成功");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("车牌号必须是一个5位号的数字");
                }
            }
        }
        bool IfHuoche(ref HuoChe hc)
        {
            bool ifrigth = false;
            bool ifContinue = true;
            
            while (ifContinue)
            {
                Console.WriteLine("请输入车的排量,输入n退出本次添加!");
              string input=Console.ReadLine();
              
              if (input.ToLower()=="n")
              {
                  ifContinue = false;
              }
              else if (int.Parse(input) >= 10 && int.Parse(input) <= 100)
              {
                  hc.Pailiang = Int32.Parse(input);
                  Console.WriteLine("请输入您的车牌号!");
                  string carname = Console.ReadLine();
                  bool name = Worke.Juge10(carname);
                  if (name)
                  {
                      hc.Carnumber = carname;
                      Console.WriteLine("请输入您的姓名!");
                      hc.Ownername = Console.ReadLine();
                      if (carinfor == null)
                      {
                          carinfor = new ArrayList();

                      }
                      Car c = (Car)hc;
                      carinfor.Add(c);
                      ifrigth = true;
                      continue;
                  }
                  else
                  {
                      Console.WriteLine("您的必须是5位的号码!");
                  }
              }
              else
              {
                  Console.WriteLine("您的排量超标,不能进!");
              }
               
                }
        
            return ifrigth;
        }
        bool ifjiaoche(ref JiaoChe jc)
        {
            bool ifrigth = false;
            bool ifContinue = true;
            while (ifContinue)
            {
                Console.WriteLine("请输入车的速度,输入n退出本次添加!");
                string input = Console.ReadLine();
                if (input.ToLower() == "n")
                {
                    ifContinue = false;
                }
                else if (int.Parse(input) > 0 && int.Parse(input) < 60)
                {

                    jc.Shudu = Int32.Parse(input);
                  

                    Console.WriteLine("请输入您的车牌号!");
                    string carname = Console.ReadLine();
                    bool name = Worke.Juge10(carname);
                    if (name)
                    {
                        jc.Carnumber = carname;
                        Console.WriteLine("请输入您的姓名!");
                        jc.Ownername = Console.ReadLine();
                        if (carinfor == null)
                        {
                            carinfor = new ArrayList();

                        }
                        Car c = (Car)jc;
                        carinfor.Add(c);
                        ifrigth = true;
                    }
                    else
                    {
                        Console.WriteLine("您的必须是5位的号码!");
                    }
                }
                else
                {
                    Console.WriteLine("您的速度超标,不能进入!");
                }

            }

            return ifrigth;
        }
        bool ifmianbao(ref MianBaoChe mb)
        {
            bool ifrigth = false;
            bool ifContinue = true;
         
            
            while (ifContinue)
            {
                Console.WriteLine("请输入车的车体装修情况(只能输入 :优 良 差),输入n退出本次添加!");
                string input = Console.ReadLine();
                bool check = CheckInfor.ifzhuangxiou(input);
                if (input.ToLower() == "n")
                {
                    ifContinue = false;
                }
                else if (check)
                {
                    mb.Zhuanxiu = input;


                    Console.WriteLine("请输入您的车牌号!");
                    string carname = Console.ReadLine();
                    bool name = Worke.Juge10(carname);
                    if (name)
                    {
                        mb.Carnumber = carname;
                        Console.WriteLine("请输入您的姓名!");
                        mb.Ownername = Console.ReadLine();
                        if (carinfor == null)
                        {
                            carinfor = new ArrayList();

                        }
                        Car c = (Car)mb;
                        carinfor.Add(c);
                        ifrigth = true;
                    }
                    else
                    {
                        Console.WriteLine("您的必须是5位的号码!");
                    }
                }
                else
                {
                    Console.WriteLine("您的装修情况不符合规定,不能进入!");
                }

            }

            return ifrigth;
        }
        public static bool Juge10(string b)
        {
            bool istwonumber = true;

            if (b.Length != 5)
            {
                istwonumber = false;
            }
            else
            {
                string j;
                int k;

                for (int i = b.Length - 1; i >= 0; i--)
                {
                    if (!char.IsLetter(b[i]))
                    {
                        j = b[i].ToString();
                        k = Convert.ToInt32(j);
                        if (k >= 0 && k <= 9)
                        { continue; }

                        else
                        {
                            istwonumber = false;
                            break;
                        }
                    }
                    else istwonumber = false;
                }
            }
            return istwonumber;
        }
    }
    class Car
    {
        /// <summary>
        /// 类型
        /// </summary>
        protected CarClass cc;

        internal CarClass Cc
        {
            get { return cc; }
            set { cc = value; }
        }
       protected string carnumber;

        public string Carnumber
        {
            get { return carnumber; }
            set { carnumber = value; }
        }
        protected string ownername;

        public string Ownername
        {
            get { return ownername; }
            set { ownername = value; }
        }
        protected Station sta=Station.未出
            ;

        public Station Sta
        {
            get { return sta; }
            set { sta = value; }
        }
    }
    class HuoChe:Car
    {
        int pailiang;

        public int Pailiang
        {
            get { return pailiang; }
            set { pailiang = value; }
        }
    }
    class JiaoChe:Car
    {
        int shudu;

        public int Shudu
        {
            get { return shudu; }
            set { shudu = value; }
        }
    }
    class MianBaoChe:Car
    {
        string zhuanxiu;

        public string Zhuanxiu
        {
            get { return zhuanxiu; }
            set { zhuanxiu = value; }
        }
    }
}
2008-07-22 13:56
yangyaming6208
Rank: 1
来 自:安徽师范大学
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-7-21
收藏
得分:0 
你要求达到什么效果?
2008-07-22 14:12
yangyaming6208
Rank: 1
来 自:安徽师范大学
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-7-21
收藏
得分:0 
好了,问题解决了
需要的话就回复我!
2008-07-22 15:16
快速回复:大家帮我解释一个动态数组错误的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019373 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved