Reputation: 65
I have a simple Serializeable class called "PlayerTutorial":
public class PlayerTutorial
{
public string ItemName { get; set; }
public string ItemTag { get; set; }
public override string ToString()
{
return $"{ItemName} {ItemTag}";
}
}
After player input I save the class to a List data, using another script which is responsible for saving and Loading.
Upon Loading, I'd like to see in the console the two strings I've saved to the list.
For example:
ItemName = "Tea", ItemTag = "HotDrink"
ItemName = "IceTea", ItemTag = "ColdDrink"
What method should I use to represent the items in my list of the class?
I tried using:
Debug.Log(string.Join(",", data.Select(d => d.ItemName)));
Only shows the first item of each saved class (e.g: "Tea", "IceTea")
I think I should try the data.SelectMany
but can't implement it correctly since I seem to be missing some parent object to do so.
Upvotes: 0
Views: 244
Reputation: 1816
You are actually overriding .ToString()
which is the result you're expecting. so to get tho that result you only need to call either the data.ToString()
or directly dont call any method, as by default the next statement: Debug.Log(string.Join(",", data));
will call .ToString()
for each element on the list.
Upvotes: 2