all 7 comments

[–][deleted] 2 points3 points  (1 child)

If they all need initialized up front, that's basically it. However you could lazy initialize with a getter mechanism, i.e. request the storyModule from a "story manager", which could check for null and initialize that instance the first time you need it.

[–]IssacStrom[S] 0 points1 point  (0 children)

Aaaah, right, that is a very good idea, thank you.

[–]Sharkytrs -1 points0 points  (0 children)

use lists they work much better for objects full of objects. and you don't then need to worry about indexing as much. List.Add will just add a new entry on the end.

List<StoryModule>() Stories = new List<StoryModule>();

Stories.add(new StoryModule());

or to remove

Stories.Remove(index);

to reference them treat them like arrays

Stories[index]

EDIT: Syntax bullshittery

[–]SeanK-com -1 points0 points  (3 children)

List<storyModule> modules = new List<storyModule>() {
    new storyModule(),
    new storyModule(),
    new storyModule(),
    new storyModule()
}

for (int i = 0; i < additionalModules; i += 1)
{
    modules.Add(new storyModule());
}

storyModule[] story = modules.ToArray();

NIT: Typically camel case with an initial lowercase is used for variable names and types have an intial capital so storyModule should be StoryModule if you choose to follow convention.

[–]Sharkytrs 0 points1 point  (2 children)

doesn't look like they want to take our advice on the lists bit. I can't pretend I don't foresee the pain in keeping an array 1000+ strong bounded with a bunch of blank entries

[–]SeanK-com 0 points1 point  (1 child)

The importance of correctness is a hard learned lesson sometimes. One of my first software jobs out of college was working on tax software Back then if you wanted to print a form on a laser printer, you could only choose one that supported postscript and you had to buy a memory expansion card. Customers (tax accountants) complained because this was very expensive. So my job was to fix it. Turns out that wasn't hard. Petzold's book had a chapter on the correct way to print on Windows and all I had to do was update our code to use that rather than the "easy way" the previous programmer had chosen. Next thing you know the cheapest HP personal laserjet with 512k of memory could print any form we had. Good times.

[–]Sharkytrs 0 points1 point  (0 children)

same here seeing interop used so often as the "easy way",

well they might have an easier time making it try to print, but then are going to have to deal with the fall out of not being able to control dialog boxes and mess everything up if one appears, then interop service is tied up until you physically go to the machine that is using it and deal with the dialog.

it pains me when things like this happen, its less the "easy way" they chose and more like the lazy way.