Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// Properties for Width and Height.
C#
public double Width {
   get { return pri_width; }
   set { pri_width = value < 0 ? -value : value; }
}
Posted
Updated 22-Apr-12 22:45pm
v2
Comments
Argonia 23-Apr-12 5:10am    
p = (evaluation)? a : b ; This is something like if the evaluation is made and if its true p gets the value a and if it isn't p gets b

This basically only allows setting a positive Width. Any negative number is converted to positive. The Abs() function would also achieve that.
http://msdn.microsoft.com/en-us/library/aa340192%28v=vs.71%29.aspx[^]
This here does the same:
C#
public double Width
     {
        get { return pri_width; }
        set { pri_width = Math.Abs(value); }
     }
 
Share this answer
 
v3
Comments
Reza Ahmadi 23-Apr-12 5:57am    
5!
The simplified version of the code

C#
public double Width 
{
     get 
     { 
          return pri_width; 
     }
     set 
     { 
          if(value < 0)
          {
                pri_width =  -value;
          }
          else
          {
                pri_width =  value;
          }
     }
  }

Read ternary operator to unserstadn original code.

if you dont understand properties:
C#
public double GetWidth
{
    
          return pri_width;
}

     public void setWidth(double value)
     {
          if(value < 0)
          {
                pri_width =  -value;
          }
          else
          {
                pri_width =  value;
          }
     }



Discaimer: solution provided by JF2015 is the best one. I am just explaining the original code.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900