資源簡介
完整的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?????????????{
????????????????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個文件信息
評論
共有 條評論