我有这个问题。假设我们有大约20个变量,每个变量都包含其他值(都是小数),现在我想从一种方法到另一种方法尽可能快地获得它。什么是实现我的目标的最快方式? 这是一些代码:从一种方法获取很多变量到另一个C#
private void button2_Click(object sender, EventArgs e)
{
decimal WStoneCost = (PriceMethod.StoneCost * AP)/100;
decimal WWoodCost = (PriceMethod.WoodCost *AP)/100;
decimal WMetalCost = (PriceMethod.MetalCost *AP)/100;
decimal WSteelCost = (PriceMethod.SteelCost *AP)/100;
decimal WPaperCost = (PriceMethod.PaperCost *AP)/100;
decimal WPotatoeCost = (PriceMethod.PotatoeCost *AP)/100;
decimal WTomatoeCost = (PriceMethod.TomatoeCost *AP)/100;
decimal WCucumberCost = (PriceMethod.CucumberCost *AP)/100;
decimal WCornCost = (PriceMethod.CornCost *AP)/100;
decimal WFlourCost = (PriceMethod.FlourCost *AP)/100;
decimal WBreadCost = (PriceMethod.BreadCost *AP)/100;
decimal WSwordsCost = (PriceMethod.SwordsCost *AP)/100;
decimal WShieldsCost = (PriceMethod.ShieldsCost *AP)/100;
decimal WCannonsCost = (PriceMethod.CannonsCost *AP)/100;
decimal WRiflesCost = (PriceMethod.RiflesCost *AP)/100;
decimal WBulletsCost = (PriceMethod.BulletsCost *AP)/100;
decimal WCowCost = (PriceMethod.CowCost *AP)/100;
decimal WhorseCost = (PriceMethod.horseCost *AP)/100;
decimal WSheepCost = (PriceMethod.SheepCost *AP)/100;
decimal WChickenCost = (PriceMethod.ChickenCost *AP)/100;
decimal WPigCost = (PriceMethod.PigCost * AP)/100;
}
我想每一个移动这些小数到一个不同的方法像这样的:
private void StoneBuy_Click(object sender, EventArgs e)
{
}
那么这将是这样做的最有效的方式?提前致谢。
为什么不建立一个类来保存这些值,创建一个类的实例并赋值,然后将该对象传递给该方法? – Alan
复制和粘贴工作得很好。 – Dirk
例如我私下需要的WStoneCost无效StoneBuy ...等他们每个人 –