How to fix : Cannot declare instance members in a static class

If I declare a C# static class below, the compiler gives me an error message. "Cannot declare instance members in a static class".

Can someone tell me how I can fix this? also I am curious why I am getting this error message?

static class HoldVariables
    float axHolder; float ayHolder;
    float bxHolder; float byHolder;
    float cxHolder; float cyHolder;
    float dxHolder; float dyHolder;

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if the class is static then so should the instance members. make sure that this class would be best utilized as static.
Fernando SotoRetiredCommented:
Hi brgdotnet;

A static class can only contain static members. Therefore static members must contain the keyword static when defined.

From Microsoft Documentation
Creating a static class is therefore basically the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated. The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

static class HoldVariables
    public static float axHolder;
    public static float ayHolder;
    public static float bxHolder;
    public static float byHolder;
    public static float cxHolder;
    public static float cyHolder;
    public static float dxHolder;
    public static float dyHolder;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
Cannot declare instance members in a static class.
It's easy to read this as instance members in general cannot be declared in a static class.

It should have read: "Cannot declare these instance members in a static class". That would have given a clue.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.