array initializer

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

Elmar Jacobs

hi folk,

i try to initilize an arry of struct. but i become always the error msg
"Array initializers can only be used in avariable or field initializer." if
i try to define the _wordbook member.

the struct is

[c++]
public class CWordbook
{
protected struct wordEntry {
public int id;
public string text;
};
....
}
[/c++]

[c++]
public class CWordbook_eng: CWordbook
{
private wordEntry [] _wordbook = {
{3, @"hallo"},
{4. @"HALLO"}
}
......
}
[/c++]


do anybody know how i can supply the initalization value to the _wordbook
member?

thank's a lot,
elmar




}
 
Try this:

private wordEntry [] _wordbook = new workEntry[] {
{3, @"hallo"},
{4. @"HALLO"};

HTH
Neil
 
thank's a lot for the answer,

but sorry it's produce the same error :(

elmar


Neil Cowburn said:
Try this:

private wordEntry [] _wordbook = new workEntry[] {
{3, @"hallo"},
{4. @"HALLO"};

HTH
Neil


Elmar Jacobs said:
hi folk,

i try to initilize an arry of struct. but i become always the error msg
"Array initializers can only be used in avariable or field initializer."
if
i try to define the _wordbook member.

the struct is

[c++]
public class CWordbook
{
protected struct wordEntry {
public int id;
public string text;
};
...
}
[/c++]

[c++]
public class CWordbook_eng: CWordbook
{
private wordEntry [] _wordbook = {
{3, @"hallo"},
{4. @"HALLO"}
}
.....
}
[/c++]


do anybody know how i can supply the initalization value to the _wordbook
member?

thank's a lot,
elmar




}
 
Heh, I think I know the problem:

{4. @"HALLO"}

should be:

{4, @"HALLO"}

You have period where a comma should be.

--Neil


Elmar Jacobs said:
thank's a lot for the answer,

but sorry it's produce the same error :(

elmar


Neil Cowburn said:
Try this:

private wordEntry [] _wordbook = new workEntry[] {
{3, @"hallo"},
{4. @"HALLO"};

HTH
Neil


Elmar Jacobs said:
hi folk,

i try to initilize an arry of struct. but i become always the error msg
"Array initializers can only be used in avariable or field
initializer."
if
i try to define the _wordbook member.

the struct is

[c++]
public class CWordbook
{
protected struct wordEntry {
public int id;
public string text;
};
...
}
[/c++]

[c++]
public class CWordbook_eng: CWordbook
{
private wordEntry [] _wordbook = {
{3, @"hallo"},
{4. @"HALLO"}
}
.....
}
[/c++]


do anybody know how i can supply the initalization value to the _wordbook
member?

thank's a lot,
elmar




}
 
ohh, sorry i saw the error with the , and a missing bracked, but i make an
mistake on calling _wordbook. i forgot the array spezification. _wordbook.id
is wrong. the correct way is _wordbook.id.

thanks a lot neil and have a nice day
elmar :)

Neil Cowburn said:
Heh, I think I know the problem:

{4. @"HALLO"}

should be:

{4, @"HALLO"}

You have period where a comma should be.

--Neil


Elmar Jacobs said:
thank's a lot for the answer,

but sorry it's produce the same error :(

elmar


Neil Cowburn said:
Try this:

private wordEntry [] _wordbook = new workEntry[] {
{3, @"hallo"},
{4. @"HALLO"};

HTH
Neil


hi folk,

i try to initilize an arry of struct. but i become always the error msg
"Array initializers can only be used in avariable or field
initializer."
if
i try to define the _wordbook member.

the struct is

[c++]
public class CWordbook
{
protected struct wordEntry {
public int id;
public string text;
};
...
}
[/c++]

[c++]
public class CWordbook_eng: CWordbook
{
private wordEntry [] _wordbook = {
{3, @"hallo"},
{4. @"HALLO"}
}
.....
}
[/c++]


do anybody know how i can supply the initalization value to the _wordbook
member?

thank's a lot,
elmar




}
 
Back
Top