Ir ao conteúdo

[Ajuda]Struct Dentro de Struct C#


SuperNov4

Posts recomendados

Postado

Structs

public struct Effect
{
public int EffectID;
public int Value;
};

public struct ItemList
{
public int ItemID;
public string ItemName;
public int Mesh;
public int WType;
public int rLevel;
public int rStr;
public int rInt;
public int rDex;
public int rCon;
public int Price;
public int EquipType;
public int Extreme;
public int Grade;
public int Effect[] Effects;
};

Code

public void LoadItemList()
{
ItemList = new ItemList[3000];
XmlDocument doc = new XmlDocument();
doc.Load("./ItemList.xml");
XmlNodeList xmlnode = doc.GetElementsByTagName("item");
for (int i = 0; i < xmlnode.Count; i++)
{
XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
ItemList[i].ItemID = Convert.ToInt32(xmlattrc[0].Value);
ItemList[i].ItemName = xmlattrc[1].Value;
ItemList[i].Mesh = Convert.ToInt32(xmlattrc[2].Value);
ItemList[i].WType = Convert.ToInt32(xmlattrc[3].Value);
ItemList[i].rLevel = Convert.ToInt32(xmlattrc[4].Value);
ItemList[i].rStr = Convert.ToInt32(xmlattrc[5].Value);
ItemList[i].rInt = Convert.ToInt32(xmlattrc[6].Value);
ItemList[i].rDex = Convert.ToInt32(xmlattrc[7].Value);
ItemList[i].rCon = Convert.ToInt32(xmlattrc[8].Value);
ItemList[i].Price = Convert.ToInt32(xmlattrc[9].Value);
ItemList[i].EquipType = Convert.ToInt32(xmlattrc[10].Value);
ItemList[i].Extreme = Convert.ToInt32(xmlattrc[11].Value);
ItemList[i].Grade = Convert.ToInt32(xmlattrc[12].Value);
ItemList[i].Effects[1].Value = 1;
}
}

o erro da quando coloca algum valor pros Effects, porque n tem o new Effect[], alguem saberia como coloca?

obrigado desde ja

  • Membro VIP
Postado

A declaração abaixo ta errada, mas acho que é só erro na hora de passar pro forum:


public [COLOR=red]int[/COLOR] Effect[] Effects;

Sobre o problema, o campo Effects não foi inicializado e tem o valor null, para não dar mais erro você precisa antes inicializar o campo, por exemplo:


public Effect[] Effects = new Effect[2];

Ou mesmo no código do metodo LoadItemList:


ItemList[i].Effects = new Effect[2];
ItemList[i].Effects[1].Value = 1;

Postado

Error 1 'server.ItemList.Effects': cannot have instance field initializers in structs

da esse erro quando coloca public Effect[] Effects = new Effect[2]; dentro da struct

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...