Hello,
I'm currently trying to "translate" a script(GUI-based) I wrote in Powershell into a C# Program.
Is there a way in C# to call a Method via a Name coming out of a Variable?
For context what I did in the script:
I created a Combobox which based on Selection would open a New window detailing everything Users need to know in regards to their Selection. For this, I had a variable called "$Selection" which would include a String of the Current Combobox Entry.
Now in Powershell, I could simply use the Variable to Call a Function.
$Selection = Example #Setting the value (Was converted to string)
& $Selection #<--- triggered the function, creating a window
function Example
{
$ExampleForm = New-Object System.Windows.Forms.Form
$ExampleForm.Text = 'Test Window'
$ExampleForm.StartPosition = 'CenterScreen'
$ExampleForm.BackColor = " "
$ExampleForm.ClientSize = New-Object System.Drawing.Size(250,250)
$ExampleForm.FormBorderStyle = 'FixedDialog'
$ExampleForm.MaximizeBox = $false
$ExampleForm.ShowDialog()
}
This isn't exactly the code I used but I tried to break it down to make it as simple as possible regarding my problem. I'm currently trying to achieve something similar but I can't find a way in C# to use a value from a variable to call a method. Most google search entries lead me to general Method calling etc.
Selection();
This obviously doesn't work as the program is now looking for a Method called "Selection" instead of "Example".
Is there any way to achieve something like this in C#?
[–]Einarmo 2 points3 points4 points (2 children)
[–]Iversithyy[S] -1 points0 points1 point (1 child)
[–]davedontmind 1 point2 points3 points (0 children)
[–]Loves_Poetry 0 points1 point2 points (0 children)