- Home /
Help with C# Arrays / lists / etc -
I'm new to C#, but have a good understanding of programming. I've never worked with arrays / lists in C# and all of the threads I'm finding seem to assume that the users have a pretty solid understanding of them.
I'm trying to create a simple 2-d array for characters...and I'm thinking in terms of taking the knowledge to multiple projects in various ways. But here's a for instance -
I want to set up a 2d(?) array to hold a character's name, dialogue string, hitpoints, and strength (just a for instance).
So if I wanted to create a character denoted by zero called Bob who would say "Hello" who has 15 hp and a strength of 2...essentially...
arr[0,0] = "Bob" // character 0 name
arr[0,1] = "Hello" // character 0 dialogue
arr[0,2] = 15 // character 0 hp
arr[0,3] = 2 //character 0 strength
How would I set this up in C#? Also, how would I recall the data...for instance, how would I be able to call the string of arr[player_number,0] to draw his name to a GUI label? (need help with accessing this as a string, not help with the GUI)
I know I'm asking for a bit, but I understand the logic, just not the syntax. Help or a 'noob' tutorial would be greatly appreciated!
Answer by Eric5h5 · Jan 22, 2012 at 07:02 PM
You don't want a 2D array, you want a class.
class Character {
string name;
string dialog;
int hp;
int strength;
}
Then you can have an array of Characters.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063253im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
using char to extract integer numbers from a list - [UnityScript] 1 Answer
How do you find an Index of an Arrayed/Listed Object? 2 Answers
Strategy for saving game 1 Answer
An Array within array 2 Answers