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!
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.
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:
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:
Error CS0081: Type parameter declaration must be an identifier not a type
Error CS0030: Cannot convert type
But ultimately I don't really want a generic, I chose Lists to be strongly typed, so why circumvent that?
Generic lists are still strongly typed- the reason you are getting all these errors is because you are treating them like they aren't!
The main problem here, is that you are using a generic method, and then assuming that the list will always be a list of strings. It doesn't like that, because it needs to remain as general as it can possibly be. In your case, you should just specify the desired type and be done with it.
Of course, since every type must have a 'ToString' method, you could still do it like this-
answered Dec 06 '11 at 07:35 AM