So, working through my project I stumbled upon a number of answers here that suggested that when possible I should use Lists instead of ArrayLists to hold data, so I went through and converted the various sections of code to support a List.
Then I got stuck.
Iām pretty new to C#, Unity and scripting in general, so pardon Newbie mistakes!
public string ListContents<inputType> (List<inputType> iList)
{
string invList = null;
if(iList != null){
foreach (string item in iList) {
invList = string.Concat (invList, " ", item);
}
if(invList != null){
invList=invList.Trim();
}
}
return invList;
}
Code is intended to to take in an Item Inventory from my Player Manager script as a param, generate a concat string of the content and chuck it back out as the return for the GUI function calling it later on.
GUI.Label (new Rect (10, 50, 250, 100), ListContents (PlayerManager.ItemInventory));
Problem is with the functionās first line, I get various errors based on the variation I try with no real understanding of which I should be working with and why theyāre throwing errors.
I started with:
public string ListContents (List iList)
Error CS0246: The type or namespace name `Listā could not be found. Are you missing a using directive or an assembly reference?
Which gave me the reminder to add āusing System.Collections.Generic;ā to the top of my code, but still it persisted. I found some answers leading down the āGenericā route:
public string ListContents<string> (List<string> iList)
Error CS0081: Type parameter declaration must be an identifier not a type
public string ListContents<inputType> (List<inputType> iList)
Error CS0030: Cannot convert type inputType' to
stringā
But ultimately I donāt really want a generic, I chose Lists to be strongly typed, so why circumvent that?