TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nigel Foster
NA
9
502
Iterating through an array using ForEach
Jan 28 2018 11:28 AM
Hello. Brilliant forum by the way. Why doesn't this work please?
public
void
InitializePack()
{
Card [] pack=
new
Card[52];
for
(
int
i = 0; i < 4; i++) {
for
(
int
j = 1; j < 14; j++) {
pack[(i*13)+j-1] =
new
Card((Suits)i, (Values)j);
}
}
foreach
(Card c
in
pack)
Console.WriteLine(c.Name);
}
c is null at first iteration. I have only seen examples of foreach iterating through arrays whose elements are defined at declaration using {}. Is this the issue?
I've not included the rest of the code as I thought you'd see this one straight away.
Thanks very much!
Reply
Answers (
5
)
array out of bounds exception in custom web server control.
Which is better?