a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

C#索引器簡單實例代碼

2020-01-24 03:31:55
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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();

            //關聯數組的方式訪問get方法

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

            //關聯數組的方式訪問set方法

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

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

            Console.ReadLine();

        }

    }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人久久一区 | 国产成人精品一区二区三区四区 | 欧美成人在线免费观看 | 激情视频在线观看 | 亚洲精选久久 | 午夜窝窝 | 国产美女在线精品免费观看 | 亚洲成人在线视频观看 | 亚洲自拍偷拍电影 | 欧美午夜视频在线观看 | 免费视频二区 | 中文字幕在线免费视频 | 激情婷婷 | 国产精品美女视频 | 狠狠色综合网站久久久久久久 | 91精品视频在线播放 | 日韩av免费在线观看 | 国产真实精品久久二三区 | 亚洲精品自在在线观看 | 国产精品视频免费观看 | 久久99国产伦子精品免费 | 国产精品国产精品国产专区不片 | 狠狠色 综合色区 | 99热在线播放 | 欧洲成人在线视频 | 日日夜夜狠狠 | 美女人人操 | 羞羞的网站在线观看 | 久久国产成人 | 在线观看免费视频91 | 免费成人在线视频网站 | 婷婷色中文网 | 成人在线观看中文字幕 | 国产精品免费在线 | 国产一区精品视频 | 欧美成在线观看 | 黄色影音| 欧美精品一区二区三区在线播放 | 在线精品亚洲欧美日韩国产 | 成人免费看电影 | 国产精品久久久久久久午夜片 |