Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's quite easy to display the contents of a struct, after initializing your struct all you need to to is make sure to specify exactly what variable within the new "User" object you want to display. This can be done by adding a period after the new "User" objects name like this:</p> <pre><code>MessageBox.Show(user.name); </code></pre> <p>This will show the "User" object's name. This can easily be done with any of the other user objects variables by replacing "name" with "email" or "age". By the way it's usually better to store things like ages's (or any number) in an "int" or "byte" because that allow's you to change the value much easyier than trying to store a number within a string. Here's an example:</p> <pre><code>public struct User { public string name; public string email; public int age; } or public struct User { public string name; public string email; //use a byte to hold a value between 0 and 255 (most people don't live to be 255) public byte age; } </code></pre> <p>And when trying to display this variable just use "ToString()" after the variables name like this:</p> <pre><code>MessageBox.Show(user.age.ToString()); </code></pre> <p>This will convert the int or byte to a string so it can be used within the "MessageBox.Show" method. Hope this helped! </p> <p>EDIT: Also when trying to display all the variables within the struct just do this:</p> <pre><code>MessageBox.Show("Name: " + user.name + Environment.NewLine + "Email: " + user.email + Environment.NewLine + "Age: " + user.age + Environment.NewLine); </code></pre> <p>This will display:</p> <pre><code>Name: FreeWind Email: abc@test.com Age: 100 </code></pre> <p>Within the messagebox.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload