- Home /
Custom class always returning Null
Hi!
I am trying to get a custom class to work in a List. So far I have a class with two strings put in a list, but the string are always Null.
Class:
[System.Serializable]
public class ArmoryInfo
{
public string weaponName;
public string weaponInfo;
public ArmoryInfo(string name, string info)
{
name = weaponName;
info = weaponInfo;
}
}
Code:
public List<ArmoryInfo> armoryInfos = new List<ArmoryInfo>();
void GetInfo()
{
armoryInfos = new List<ArmoryInfo>();
for (int i = 0; i < 3; i ++)
{
armoryInfos.Add (new ArmoryInfo("Please", "Work"));
}
}
Does anyone know why this is returning null? I think it has something to do with me not using the class correctly...
Thanks
Comment
Best Answer
Answer by ffxz7ff · Nov 24, 2013 at 05:59 PM
Change
name = weaponName;
info = weaponInfo;
to
weaponName = name;
weaponInfo = info;
I can't believe I didn't try that out! Thanks, now it works :)
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Objects not being added to a list 2 Answers
Generic List 'Contains' always returns false 1 Answer
How can i store the Amount of an item i have in an inventory? 0 Answers