troubleshooting Question

Singleton example 2

Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland asked on
C#Microsoft Visual Studio
10 Comments1 Solution88 ViewsLast Modified:
How do I call an instance of this class using C# in Visual Studio 2017?  At the moment I have a console App.  In the static main method I have this code, but can't invoke the Inventory class due to its protection level.

static void Main(string[] args)
        {
            Inventory I1 = new Inventory();
        }

I've seen a similar question here, but I want to understand what's happening rather than just copy and paste https://www.experts-exchange.com/questions/21783726/Singleton-example.html
I'd like to see the class invoked successfully once then produce an error message when I try to invoke it a second time.

    private static readonly Lazy<Inventory> instance = new Lazy<Inventory>(() => new Inventory());
    private Inventory()
    { }
    public static Inventory Instance
    {
        get { return instance.Value; }
    }
    public void LookupProduct(string upc)
    {

    }
ASKER CERTIFIED SOLUTION
AndyAinscow
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros