• 大小: 1.29MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-03
  • 语言: C#
  • 标签: C#  宠物商店  源代码  

资源简介

完整的C#宠物商店小实例代码,简洁易学习,交流拍砖~

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PetsShop
{
    public class Pet
    {
        public String name;
        public String color;
        public int age;
    }
    public class Cat : Pet
    {//各个字段必须为public否则程序无法通过//
        public Cat(String na String co int a)//前边必须加上public否则生成实例时报错说不包含*个参数的构造函数//
        {
            name = na;
            color = co;
            age = a;
        }
        /// 
        //属性/ /
        /// 

        public String Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        public String Color
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
            }
        }
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                age = value;
            }
        }


    }
    public class Dog : Pet
    {
        public Dog(String na String co int a)
        {
            name = na;
            color = co;
            age = a;
        }
        public String Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        public String Color
        {
            get
            {
                return color;
            }
            set
            {
                color = value;
            }
        }
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                age = value;
            }
        }

    }
    public class PetShop
    {  //将petshop设置为的所有字段和方法设为static是为了在显示窗口时用类名调用它的字段和方法//
        public static  int maxlen = 100;
        public static  Pet[] pets = new Pet[100];//宠物店最大容纳量//
        public static  int count = 0;
        
        public static int getCount()//获得当前宠物数量//
        {
            return count;
        }
        public static bool AddPet(Pet e)//添加宠物//
        {
            if (count < maxlen)
            {
                if (e is Cat)//判断类型用is//
                {
                    pets[count++] = e;
                    return true;
                }
                else if (e is Dog)
                {
                    pets[count++] = e;
                    return true;
                }
                else return false;//必须添加该条语句,使if else语句完整否则报告并非所有输入都返回值的错误//
            }
            else return false;
        }
        public static int Find(String na String co int a)//查询宠物//
        {
            int i;
            Cat cc;Dog dd;
        
               

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-09-09 16:45  PetsShop\
     目录           0  2011-09-11 00:38  PetsShop\PetsShop\
     文件        1332  2011-09-09 18:44  PetsShop\PetsShop.sln
     文件       43008  2011-09-13 22:23  PetsShop\PetsShop.suo
     目录           0  2011-09-09 18:57  PetsShop\PetsShop\bin\
     目录           0  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\
     目录           0  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\
     目录           0  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\Application Files\
     目录           0  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\Application Files\PetsShop_1_0_0_2\
     文件      235008  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\Application Files\PetsShop_1_0_0_2\PetsShop.exe.deploy
     文件        6615  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\Application Files\PetsShop_1_0_0_2\PetsShop.exe.manifest
     文件        5557  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\PetsShop.application
     文件      428936  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\app.publish\setup.exe
     文件        1889  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\PetsShop.application
     文件      235008  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\PetsShop.exe
     文件        3018  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\PetsShop.exe.manifest
     文件       75264  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\PetsShop.pdb
     文件        1889  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\PetsShop.vshost.application
     文件       11600  2011-09-13 19:02  PetsShop\PetsShop\bin\Debug\PetsShop.vshost.exe
     文件        3018  2011-09-13 14:59  PetsShop\PetsShop\bin\Debug\PetsShop.vshost.exe.manifest
     文件        5989  2011-09-13 14:57  PetsShop\PetsShop\Class1.cs
     文件        3876  2011-09-13 14:35  PetsShop\PetsShop\Form1.cs
     文件       17406  2011-09-13 14:35  PetsShop\PetsShop\Form1.Designer.cs
     文件      309255  2011-09-13 14:35  PetsShop\PetsShop\Form1.resx
     文件        2382  2011-09-10 23:14  PetsShop\PetsShop\Form2.cs
     文件        9757  2011-09-09 19:29  PetsShop\PetsShop\Form2.Designer.cs
     文件        5817  2011-09-09 19:29  PetsShop\PetsShop\Form2.resx
     文件        2087  2011-09-11 00:51  PetsShop\PetsShop\Form3.cs
     文件        9755  2011-09-10 23:07  PetsShop\PetsShop\Form3.Designer.cs
     文件        5817  2011-09-10 23:07  PetsShop\PetsShop\Form3.resx
     文件        2540  2011-09-11 00:52  PetsShop\PetsShop\Form4.cs
............此处省略37个文件信息

评论

共有 条评论