My task:
To calculate the values using the formula (60 * 1,5 ^ (the value of TextBox-1)), which is located in the library and is described as:
public class Cost { public static int Cost_Of_MetalMine(int MM_Metal, int MM_Silicon) { return MM_Metal = (int)(60 * Math.Pow(1.5,значение TextBix - 1)); } }
I need to pass the TextBox value to the formula. I am trying to do all this through a delegate, declare in the library:
namespace SCore { public delegate int GetComboboxindex(int SelectedIndex); ... ... }
You'll get a method to get the TextBox value into a separate class:
namespace Sim { class Operations { public static void MFD_GetSelectedIndex(int SI_LevelOfBuilding, int SI_NameOfBuilding) { KalkulatorStoimosti chc = new KalkulatorStoimosti(); SI_LevelOfBuilding = int.Parse(chc.LevelOfSelectedBuilding.Text); // TextBox SI_NameOfBuilding = chc.SelectedIndexOfBuilding.SelectedIndex; // ComboBox } } }
And pass it on:
namespace Sim { public partial class KalkulatorStoimosti : Form { public int SI_LevelOfBuilding; public int SI_NameOfBuilding; public KalkulatorStoimosti() { InitializeComponent(); GetComboboxindex Get_Combobox_Index_Method = Operations.MFD_GetSelectedIndex(SI_LevelOfBuilding,SI_NameOfBuilding); Core.CoreMethod(Get_Combobox_Index_Method); } } }
The library accepts:
public static void CoreMethod (GetComboboxindex CallBackFinction_GetIndex) { CallBackFinction_GetIndex(); }
I did not complete the passed arguments in the function because I got confused ... because here:
GetComboboxindex Get_Combobox_Index_Method = Operations.MFD_GetSelectedIndex(SI_LevelOfBuilding,SI_NameOfBuilding);
writes: implicit conversion of void to int is impossible. I do not understand how to correct this situation. I tried everything I knew ... Explain whether I'm on the right path? Do you do it right? How can I transfer the value of TxtBox to the library function? ...
UPD1 : @Flammable , thanks for the help, I would like to ask how to tie the switch to the library method? initialization of variables is needed for transmission, but using switch, variables are initialized only in it that is not right. What better way to do? @alexlz , thanks for the info. I'll try after I deal with this problem. I was interested;) I want to ask in advance that it is more productive to pass a parameter to a function or use
tuple<T,T>`
Library function:
public static void Cost_Of_SelectedBuiding(out int MM_Metal, out int MM_Silicon, int SI_LevelOfBuilding, int SI_SelectedComboboxIndex) { //MM_Metal = (int)(60 * Math.Pow(1.5, SI_LevelOfBuilding - 1)); //MM_Silicon = (int)(15 * Math.Pow(1.5, SI_LevelOfBuilding - 1)); switch (SI_SelectedComboboxIndex) { case 0: MM_Metal = (int)(60 * Math.Pow(1.5, SI_LevelOfBuilding - 1)); MM_Silicon = (int)(15 * Math.Pow(1.5, SI_LevelOfBuilding - 1)); break; }