-1
I would like to make a system that when informed an integer number (Int) it performs a certain function.
Int Input > Find Object Function > Transform int in a name > executes the function with that name.
Example: It’s not a functional code
public class Main
{
public static void AcharObjeto(int id)
{
for (int Type = 0; Type < Objects.ObjectsList.Length; Type++)
if (id == Convert.ToInt32(Objects.ObjectsList[Type,1]))
// Daqui para baixo não funciona e essa e a pergunta!!
foreach(Obj in Objects)
{
if(Obj.toString() == Objects.ObjectsList[Type,0])
Obj();
}
}
}
public class Objects
{
public static string[,] ObjectsList = new string[1, 2] {
{ "Toalha", "1" }
};
public static void Toalha()
{
Debug.WriteLine("Toalha");
}
}
I don’t know if you can understand but I’d like to know how to do that! I made this code on market theme like the guy goes there and reads the code, then he has to find it in a code list and assimilate it with the function that makes mark the price or something like that.
An easier way to understand:
string namefunc = "teste"; Main.namefunc();
ANSWERS IN C, PLEASE
the demonstration code makes it well understand how I would like to do. I can not explain but I will try. I want to call the code Acharobjeto() passing the id of the towel. I want to call the function that is in the class Objectcs.Towel(). I want to do this q the sample codide explains exactly what I want to do. I can’t explain it better. ======== if possible explain better the part of Typedaclasseondeestaometodo because I only have one class and I can’t use this because the code and Static
– Zehous
@Zehous, in this case you can do
typeof(SuaClasse)
.– tvdias
@Zehous added logic to his code.
– tvdias
ps: also note that you are making incorrect use of the .Length. array I made the correction in the demo.
– tvdias
Obg Also Worked.
– Zehous
@Zehous in this case may accept the answer and vote in favour
– tvdias
yes I just did. ps: (I found out now that this existed)
– Zehous
How can I pass int as parameter pq function.Invoke(null, 0); does not work
– Zehous
According to the documentation, the 2nd property of
Invoke
is an array of objects. Therefore, it is necessary to dofuncao.Invoke(null, new object[]{ 0 });
– tvdias