Results 1 to 5 of 5

Thread: [RESOLVED] Initialization check

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Resolved [RESOLVED] Initialization check

    Hi,

    So I have this static class with a couple of static functions.
    This class, though, needs to be initialized first by loading some data.
    Figured I could use a static boolean called init and throw an exception in each function if init is not true.
    This would require me to do a check in every function.

    It's doable, but is there a more efficient way to do this?

    Thanks
    Delete it. They just clutter threads anyway.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Initialization check

    Is there a genuine reason that this class is static? It sounds like it would make sense to require the user to create an instance by passing this required data to the constructor.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Initialization check

    It's a settings container and initially that's the way I designed it (not static).
    But as it's built only to load one set of settings and it's easier to access statically, I figured, why not?
    Last edited by TheBigB; Sep 28th, 2010 at 02:06 PM.
    Delete it. They just clutter threads anyway.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Initialization check

    Quote Originally Posted by TheBigB View Post
    I figured, why not?
    I guess this thread is the answer to that question.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Initialization check

    I guess I'm gonna be stubborn and do some copying and pasting.
    I'd rather code using Settings.Function than Program.Settings.Function.
    God, I'm lazy

    Was just wondering if there was an easier way.
    Thanks
    Delete it. They just clutter threads anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width