lundi 14 juin 2021

Array of objects: how to get names of objects inside array?

For example, I have such method:

public void ExecuteExampleMethod()
{
    var exampleId1 = 1;
    var exampleId2 = 2
    ExampleMethod(0, exampleId1, exampleId2)
}

public void ExampleMethod(int exampleId, params object[] parameters)
{
   foreach(var parameter in parameters)
   {
     Console.WriteLine($"{parameter.Name} {parameter.Value}")
   }
   
}
  

So, I need to output like this:

"exampleId1 1"
"exampleId2 2"

How can I do it? I tried reflection = parameter.GetType() - but didn't find anything useful.





Aucun commentaire:

Enregistrer un commentaire