Click here to Skip to main content
15,913,587 members
Home / Discussions / C#
   

C#

 
GeneralRe: Event Handler Pin
AlexB473-Jan-10 4:05
AlexB473-Jan-10 4:05 
Questionword file Not lock...? Pin
koolprasad20032-Jan-10 23:48
professionalkoolprasad20032-Jan-10 23:48 
QuestionI'm Baffled Again Pin
Roger Wright2-Jan-10 21:49
professionalRoger Wright2-Jan-10 21:49 
AnswerRe: I'm Baffled Again Pin
Richard MacCutchan2-Jan-10 22:00
mveRichard MacCutchan2-Jan-10 22:00 
AnswerRe: I'm Baffled Again Pin
Abhinav S2-Jan-10 22:06
Abhinav S2-Jan-10 22:06 
AnswerRe: I'm Baffled Again Pin
Rob Philpott2-Jan-10 22:17
Rob Philpott2-Jan-10 22:17 
GeneralRe: I'm Baffled Again Pin
Roger Wright4-Jan-10 1:46
professionalRoger Wright4-Jan-10 1:46 
AnswerRe: I'm Baffled Again Pin
DaveyM692-Jan-10 23:56
professionalDaveyM692-Jan-10 23:56 
Hi again Roger,

Basically, it's easiest to have a private backing field.
private int myValue;
In the constructor, take this as a parameter and assign to the field
public MyClassOrStruct(int myValue)
{
    this.myValue = myValue;
}
Then have a readonly property that returns the field
public int MyValue
{
    get { return myValue; }
}
In the case of a value that is calculated from other given values (such as Vertex1...), just provide the property and do the calculation in the getter
public int Square
{
    get { return myValue * myValue; }
}


Your triangle would now look something like this - I've used your calculations shown so you may need to ammend to include Rob's correction above.
using System;
using System.Drawing;

namespace ShapesLibrary
{
    // Immutable struct
    public struct Triangle
    {
        public static readonly Triangle Empty = new Triangle();

        private Point anchor;
        private float angle;
        private int radius;

        public Triangle(Point anchor, Int32 radius, float angle)
        {
            this.anchor = anchor;
            this.angle = angle;
            this.radius = radius;
            // check values for validity and throw ArgumentOutOfRangeException if necessary
        }

        public Point Anchor
        {
            get { return anchor; }
        }
        public float Angle
        {
            get { return angle; }
        }
        public float Radius
        {
            get { return radius; }
        }
        public Point Vertex1
        {
            get
            {
                return new Point(
                    (int)(radius * Math.Cos(angle)),
                    (int)(radius * Math.Sin(angle)));
            }
        }
        public Point Vertex2
        {
            get
            {
                return new Point(
                    (int)(radius * Math.Cos(angle + 120)),
                    (int)(radius * Math.Sin(angle + 120)));
            }
        }
        public Point Vertex3
        {
            get
            {
                return new Point(
                    (int)(radius * Math.Cos(angle + 240)),
                    (int)(radius * Math.Sin(angle + 240)));
            }
        }
    }
}


Dave

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

QuestionRe: I'm Baffled Again Pin
Abhinav S3-Jan-10 0:03
Abhinav S3-Jan-10 0:03 
AnswerRe: I'm Baffled Again Pin
DaveyM693-Jan-10 0:28
professionalDaveyM693-Jan-10 0:28 
GeneralRe: I'm Baffled Again Pin
Rob Philpott3-Jan-10 0:35
Rob Philpott3-Jan-10 0:35 
GeneralRe: I'm Baffled Again Pin
DaveyM693-Jan-10 0:51
professionalDaveyM693-Jan-10 0:51 
GeneralRe: I'm Baffled Again Pin
OriginalGriff3-Jan-10 1:09
mveOriginalGriff3-Jan-10 1:09 
GeneralRe: I'm Baffled Again Pin
Abhinav S3-Jan-10 1:13
Abhinav S3-Jan-10 1:13 
GeneralRe: I'm Baffled Again Pin
OriginalGriff3-Jan-10 1:23
mveOriginalGriff3-Jan-10 1:23 
GeneralRe: I'm Baffled Again Pin
DaveyM693-Jan-10 1:15
professionalDaveyM693-Jan-10 1:15 
GeneralRe: I'm Baffled Again Pin
DaveyM693-Jan-10 1:14
professionalDaveyM693-Jan-10 1:14 
GeneralRe: I'm Baffled Again Pin
Rob Philpott3-Jan-10 1:20
Rob Philpott3-Jan-10 1:20 
GeneralRe: I'm Baffled Again Pin
OriginalGriff3-Jan-10 1:25
mveOriginalGriff3-Jan-10 1:25 
GeneralRe: I'm Baffled Again Pin
Rob Philpott3-Jan-10 1:35
Rob Philpott3-Jan-10 1:35 
GeneralRe: I'm Baffled Again Pin
OriginalGriff3-Jan-10 1:48
mveOriginalGriff3-Jan-10 1:48 
GeneralRe: I'm Baffled Again Pin
Rob Philpott3-Jan-10 6:35
Rob Philpott3-Jan-10 6:35 
GeneralRe: I'm Baffled Again Pin
OriginalGriff3-Jan-10 7:18
mveOriginalGriff3-Jan-10 7:18 
GeneralRe: I'm Baffled Again Pin
DaveyM693-Jan-10 1:38
professionalDaveyM693-Jan-10 1:38 
JokeProblem Solved! Pin
DaveyM693-Jan-10 2:05
professionalDaveyM693-Jan-10 2:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.