首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# switch()话语分支过多时,有没有别的方式实现呢

2012-09-24 
C# switch()语句分支过多时,有没有别的方式实现呢?C# codeint flag 1private void timer1_Tick(object

C# switch()语句分支过多时,有没有别的方式实现呢?

C# code
int flag = 1;        private void timer1_Tick(object sender, EventArgs e)        {            string str = "Properties.Resources._01";            str.Replace(@"""","");            switch (flag)            {                case 1:                    this.pictureBox1.Image = Properties.Resources._01;                    flag = 2;                    break;                case 2:                    this.pictureBox1.Image = Properties.Resources._02;                    flag = 3;                    break;                case 3:                    this.pictureBox1.Image = Properties.Resources._03;                    flag = 4;                    break;                case 4:                    this.pictureBox1.Image = Properties.Resources._04;                    flag = 5;                    break;                case 5:                    this.pictureBox1.Image = Properties.Resources._05;                    flag = 6;                    break;                ......................................................                default :                    break;            }        }

我要实现的功能是读取保存在Resource文件夹先的图片,然后轮流显示,从而实现动态效果。存在的问题是图片很多的话,switch()语句的分支过多,会不会影响程序效率呢,有没有其他方式来实现呢?

[解决办法]
好吧,又错了
我进了vs,应该是这样:
this.pictureBox1.Image = (Image)Properties.Resources.ResourceManager.GetObject("_0" + flag);
flag++;

热点排行