麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 編程 > C# > 正文

C#索引器簡(jiǎn)單實(shí)例代碼

2020-01-24 03:31:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

public class Fruit

{

        string peach = "a round juicy fruit that has a soft yellow or red skin and a large hard seed in the center, or the tree that this fruit grows on";

        string orange = "a round fruit that has a thick orange skin and is divided into parts inside";

        string banana = "a long curved tropical fruit with a yellow skin";

        string apple = "a hard round fruit that has red, light green, or yellow skin and is white inside ";

        public string this[string fruitName]

        {

            get

            {

                switch (fruitName)

                {

                    case "peach":

                        return peach;

                    case "orange":

                        return orange;

                    case "banana":

                        return banana;

                    case "apple":

                        return apple;

                    default:

                        throw new Exception("wrong fruit name");

                }

            }

            set

            {

                switch (fruitName)

                {

                    case "peach":

                        peach = value;

                        break;

                    case "orange":

                        orange = value;

                        break;

                    case "banana":

                        banana = value;

                        break;

                    case "apple":

                        apple = value;

                        break;

                    default:

                        throw new Exception("wrong fruit name");

                }

            }

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            Fruit f = new Fruit();

            //關(guān)聯(lián)數(shù)組的方式訪問(wèn)get方法

            Console.WriteLine(f["peach"]);

            //關(guān)聯(lián)數(shù)組的方式訪問(wèn)set方法

            f["peach"] = "I like to eat peach.";

            Console.WriteLine(f["peach"]);

            Console.ReadLine();

        }

    }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 视频在线中文字幕 | www.91pron | 国产一级在线免费观看 | 日韩美女电影 | 羞羞的视频免费在线观看 | 国产在线观看免费视频软件 | 国产正在播放 | 国产免费久久久久 | 精品一区在线视频 | 精品一区二区电影 | 欧美特黄a | 免费在线性爱视频 | 中文字幕伦乱 | 黄色片快播 | 一级国产航空美女毛片内谢 | 毛片韩国| 色播视频在线播放 | 视频一区二区三区中文字幕 | 国产一区二区国产 | 91成人在线免费视频 | 久久国产精品99国产 | 一级做a爱片久久毛片a高清 | 91香蕉影视| 日本精品中文字幕 | 久草高清视频 | 国产在线观看91精品 | 黄色片快播 | 日韩一级片 | 毛片小网站 | www.91sese| 最新影院| 91麻豆精品国产91久久久点播时间 | 欧美女人天堂 | 中文字幕在线观看免费视频 | aa级黄色片 | 亚洲午夜国产 | 深夜福利视频绿巨人视频在线观看 | 午夜精品久久久久久毛片 | 91精品国产综合久久男男 | 久久99精品久久久久久青青日本 | sese在线视频 |