I created a struct:
public struct User {
public string name;
public string email;
public string age;
}
Then create one:
User user = new User();
user.name = "Freewind";
user.email = "abc@test.com";
user.age = 100;
Then display it:
MessageBox.Show(user.ToString());
I hope it can print all of the fields of the user struct, but it’s not. It just shows:
MyApp.User
Is there a easy way to display all the fields of a struct?
Override the
ToStringmethod on your struct:Note that this is not automatic and you will have to manually add any fields/properties to the string.
With reflection you can do something like this: