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

1 Answer

1

Change

name = weaponName;
info = weaponInfo;

to

weaponName = name;
weaponInfo = info;

I can't believe I didn't try that out! Thanks, now it works :)