I want to convert an item selected by a user in a combo box into executable assembly, so I can output directly from a class, without writing individual if statements. I did search this up and could not find an answer that worked for me. The error message that I got for lblOne.Text = cboComboBox.SelectedItem.aString is: 'object' does not contain a definition for 'aString' and no accessible extension method 'aString' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?). Sorry if I posted too much code, this is my second time posting here. Here is my attempt to code it:
// in public partial class Form1: Form : A one = new A("One", "Cool");
public class A
{
// Instance Variables
string Name;
string Info;
// Constructor Declaration of Class
public A(string Name, string Info)
{
this.Name = Name;
this.Info = Info;
}
// method 1
public string getName()
{
return Name;
}
// method 2
public string getInfo()
{
return Info;
}
//output to label
public string aString()
{
return ("Name: " + this.getName() + "\n" +
"Info: " + this.getInfo() + "\n");
}
private void btnStats_Click(object sender, EventArgs e)
{
lblOne.Text = cboComboBox.SelectedItem.aString();
//doesn't actually work
//what I want it to be in code: lblOne.Text = one.aString();
}