Why do I get this message ? :/

+2 Orkun Erbil · January 11, 2015



      Why do I get this message when I run the application ?


Post a Reply


Oldest  Newest  Rating
+1 Vincenzo Marcella · January 12, 2015
Although I'm not familiar with C#, It seems that you're setting the button to display the name of the class to string, and not the String you're passing through its parameters. What you want to do is pass through a String variable inside MessageBox.show() from the MyClass class and not pass through the class name transformed into a string if that makes sense
0 Orkun Erbil · January 12, 2015
Yes, that exactly what I want and actually I corrected it but I didn't understand how I get the class name inside MessageBox.show() .
+2 Eugene Botma · January 12, 2015
you're trying to convert the MyClass object to a string, and by default, that returns the name of the class. I'm assuming that you want it to show the name that you set when you instantiate the mc object. In that case, you can just try MessageBox.Show(mc.Name);

You set the Name property, you have to access that same property again to get it's value.

The following is way out of scope and probably a bit advanced if you're only starting out with c# now, but it might  be useful for future reference.

In a class, you can override the ToString method to return a string of your choice. for example:

class Person
public string Name { get; set; }
public string Surname {get; set;}

public Person(string Name, string Surname)
this.Name = Name;
This.Surname = Surname;

public override string ToString()
return Name +" "+Surname;


Person someone = new Person("Eugene", "Botma");
MessageBox.Show(someone.Name);//This will show "Eugene"
MessageBox.Show(someone.Surname);//This will show "Botma"
MessageBox.Show(someone.ToString());//This will show "Eugene Botma"
  • 1



C# is an object-oriented language designed for improving the development of web applications.