C # System.Collections.Generic.List`1 [System.String]

So, I'm starting a web development course at septemeber, and we're going to program in C #. So I started to study it, so I have some experience with this. Now I have ~ 2 years of experience in HTML, CSS and PHP, so I immediately chose C #.

I study classes, and I study, not read. I decided to create a small console RPG for learning classes. I have a main game, but I have a problem. I am trying to display the inventory of players from the Player class in another class.

I use the List to store players ’inventory.

public List<string> inventory = new List<string>();

This is in the player class file.

Then in the store class I do:

Player player = new Player();

To create a new object to access the player class. Then, to add something to the list in the store, I do:

player.inventory.Add("Axe");

player.inventory(); , - System.Collections.Generic.List`1 [System.String].

-, ? ?

+5
5

, . ToString() List .

, , , PHP, , ? :

string.Join(", ", player.inventory);
+4

, , , - : -

foreach(var i in player.Inventory)
{
     Console.WriteLine(i);
}

*

Console.Write(string.Join(System.Environment.NewLine, player.Inventory));
+2

, :

string items = string.Join(Environment.NewLine, player.inventory);

Console.WriteLine(items);

ToString() ( Console.WriteLine) , . System.Collections.Generic.List`1 [System.String]. .

+1

foreach . .

- :

foreach(var i in Player.Inventory)
{
    Console.WriteLine(i);
}
0

, :

foreach (string inventoryItem in player.inventory)
{
     Console.WriteLine(inventoryItem);
}

player.inventory .

0

All Articles