Setting a range value in a struct

Posted on 2004-10-22
Last Modified: 2010-04-15
hi i have the following struct

      public struct Camera
            public Coordinate Coordinate;
            public int Pitch;
            public int Altitude;
            public int Direction;
            public int Distance;

what i want to is when the value is set for Direction i want to only allow 1 to 360 positive range to be allowed, how would i do this within my sruct so that i do not have to include any validation code on all the pages which use the struct.

I hope this makes sence
Question by:Robinsonx6
    LVL 8

    Accepted Solution


    Might want to rewrite it using Direction as a property:

    struct Camera
          private int direction;

          public int Direction
                      if(value < 0 || value > 360)
                            throw new ArgumentException("Value must be between 0 and 360");
                      this.direction = value;


    LVL 2

    Author Comment

    sorry for delay as lost all internet due to crazy lorry driver crashing into telecoms pole outside office.

    will i need to put any code on the pages which use the struct?
    LVL 8

    Expert Comment

    I'm not quite sure what you mean. You can just use this code for the struct and use it like you used the struct before. Is that what you want to know?

    Hope the lorry driver is ok ;)

    LVL 2

    Author Comment

    lorry driver is ok but as he was pissed and put me 6 days behind deadline i would like to kill him, lol, it took so long to repasir as this is mauritius!!!!

    yeah that is what i meant ill try it shortly.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles a…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now