[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Setting a range value in a struct

Posted on 2004-10-22
4
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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