[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Setting a range value in a struct

Posted on 2004-10-22
4
Medium Priority
?
218 Views
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
chears
0
Comment
Question by:Robinsonx6
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Razzie_ earned 1000 total points
ID: 12379076
Hi,

Might want to rewrite it using Direction as a property:

struct Camera
{
      private int direction;

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

HTH,

Razzie
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12408318
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?
0
 
LVL 8

Expert Comment

by:Razzie_
ID: 12408480
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 ;)

Razzie
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12408699
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.

thanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

591 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