如何在c#中生成2种情况而不是1种情况

本文关键字:情况 1种 2种 | 更新日期: 2023-09-27 18:04:20

我正在尝试生成2个案例。我想让它选择2种情况

my code

#region IronTiger Boss
            if (Owner.Name == "IronTiger")
            {
                byte times = (byte)Kernel.Random.Next(1, 3);
                byte ref_times = (byte)Kernel.Random.Next(1, 6);
                for (byte i = 0; i < times; i++)
                {
                    uint Uid = 0;
                    byte type = (byte)Kernel.Random.Next(1, 28);
                    switch (type)
                    {
                        case 1:
                            Uid = 824020;    
                            break;
                        case 2:
                            Uid = 824019;    
                            break;
                        case 3:
                            Uid = 824018;    
                            break;
                        case 4:
                            Uid = 823060;    
                            break;   
                        case 5:
                            Uid = 823061;    
                            break;
                        case 6:
                            Uid = 823060;    
                            break;
                        case 7:
                            Uid = 823059;    
                            break;
                        case 8:
                            Uid = 823058;    
                            break;
                        case 9:
                            Uid = 822072;    
                            break;
                        case 10:
                            Uid = 822071;    
                            break;
                        case 11:
                            Uid = 821033;    
                            break;
                        case 12:
                            Uid = 820076;    
                            break;
                        case 13:
                            Uid = 820075;    
                            break;
                        case 14:
                            Uid = 820074;    
                            break;
                        case 15:
                            Uid = 820073;    
                            break;
                        case 16:
                            Uid = 800917;    
                            break;
                        case 17:
                            Uid = 800811;    
                            break;
                        case 18:
                            Uid = 800810;    
                            break;
                        case 19:
                            Uid = 800725;    
                            break;
                        case 20:
                            Uid = 800618;    
                            break;
                        case 21:
                            Uid = 800522;    
                            break;
                        case 22:
                            Uid = 800422;    
                            break;
                        case 23:
                            Uid = 800255;    
                            break;
                        case 24:
                            Uid = 800255;    
                            break;
                        case 25:
                            Uid = 800142;    
                            break;
                        case 26:
                            Uid = 800111;    
                            break;
                        case 27:
                            Uid = 800020;    
                            break;
                        case 28:
                            Uid = 821034;    
                            break;    
                    }
                    if (Uid != 0)
                    {
                        killer.Owner.Inventory.Add(Uid, 0, 1);
                        DeadPool.Kernel.SendWorldMessage(new DeadPool.Network.GamePackets.Message("Congratulations! " + killer.Name + " has killed " + Name + " and dropped! " + Database.ConquerItemInformation.BaseInformations[Uid].Name + "!", System.Drawing.Color.White, 2011), Program.Values);
                        return;
                    }    
                }
            }
            #endregion  

当它完成时,它只给我一个case。我想让它生成2种情况,而不是1种。我怎么能解决这个问题,也,我如何添加更多的情况?

如何在c#中生成2种情况而不是1种情况

if (Uid != 0)
{
  killer.Owner.Inventory.Add(Uid, 0, 1);
  DeadPool.Kernel.SendWorldMessage(new DeadPool.Network.GamePackets.Message("Congratulations! " + killer.Name + " has killed " + Name + " and dropped! " + Database.ConquerItemInformation.BaseInformations[Uid].Name + "!", System.Drawing.Color.White, 2011), Program.Values);
  return;
}

看到那里的return了吗?你知道它的作用吗?当找到一个值时返回,因此不会执行第二次循环。

您应该学习如何使用调试器来检查代码,这些问题立即变得清晰。

相关文章: