language text array

  • Thread starter Thread starter Elmar Jacobs
  • Start date Start date
E

Elmar Jacobs

hi folk,

i try to realise a dict arry for different languages in my program. for
example

private static dictEntry [] _dict = {
{osdtext_intro, @"hallo world", @"hallo welt"};
};

with dictEntry =

public struct dictEntry {
public int ID;
public string [] text = new string[2];
};

My problem: I can't allocate memory for the strings in the dictEntry. But my
main target is to realise a structure like _dict.
Can anybody help me?

Lot of thanks,
elmar
 
Elmar Jacobs said:
i try to realise a dict arry for different languages in my program. for
example

private static dictEntry [] _dict = {
{osdtext_intro, @"hallo world", @"hallo welt"};
};

with dictEntry =

public struct dictEntry {
public int ID;
public string [] text = new string[2];
};

My problem: I can't allocate memory for the strings in the dictEntry. But my
main target is to realise a structure like _dict.
Can anybody help me?

You need a constructor in your struct, eg:

public dictEntry (int ID, string[] text)
{
this.ID = ID;
this.text = text;
}

and change you _dict definition to:

private static dictEntry[] _dict =
{ new dictEntry(osdtext_intro, "hallo world", "hallo welt")};

Do you have any reason for making dictEntry a struct rather than a
class, by the way?
 
yes, i think so.
over the class construct you need many ram memory on run time. if you work
with struct construct you waste only flash memory. the other plus point for
the struct construct, is that you don't neet initalisize time on boot up
sequenz.

Jon Skeet said:
Elmar Jacobs said:
i try to realise a dict arry for different languages in my program. for
example

private static dictEntry [] _dict = {
{osdtext_intro, @"hallo world", @"hallo welt"};
};

with dictEntry =

public struct dictEntry {
public int ID;
public string [] text = new string[2];
};

My problem: I can't allocate memory for the strings in the dictEntry. But my
main target is to realise a structure like _dict.
Can anybody help me?

You need a constructor in your struct, eg:

public dictEntry (int ID, string[] text)
{
this.ID = ID;
this.text = text;
}

and change you _dict definition to:

private static dictEntry[] _dict =
{ new dictEntry(osdtext_intro, "hallo world", "hallo welt")};

Do you have any reason for making dictEntry a struct rather than a
class, by the way?
 
Elmar Jacobs said:
yes, i think so.
over the class construct you need many ram memory on run time. if you work
with struct construct you waste only flash memory.

Um, I really don't think so. Bear in mind that by the time you're
putting the structs into an array they'll be in the heap anyway, but I
very much doubt that the stack and the heap use significantly different
portions of memory in the first place.
the other plus point for the struct construct, is that you don't neet
initalisize time on boot up sequenz.

Eh? In what way? If you need to create a class instance or a struct
during boot-up, you need to create it. If you don't, you don't. Whether
it's a class or a struct has nothing to do with it.
 
Back
Top