Skip to content

Initialize Handler Array With Initial Value #302

@JasonBock

Description

@JasonBock

Describe the solution you'd like
When I add a handler to the list, if the list is null, I first do new(), and then I add the new handler. If the list is null, there is a constructor overload to List<> that takes a IEnumerable<T> (and also checks/casts to ICollection<T>). It might be more efficient to, instead of what I'm currently doing:

if (this.Expectations.handlers0 is null ) { this.Expectations.handlers0 = new(); }
this.Expectations.handlers0.Add(@handler);

...to do this instead:

if (this.Expectations.handlers0 is null ) { this.Expectations.handlers0 = new([@handler]); }
else { this.Expectations.handlers0.Add(@handler); }

This would be a micro-optimization at best, so I won't do this unless I can see a clear "win" with this approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions