Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
QuestionCommunicating with unmanaged DLL Pin
Member 1041441717-Jan-17 2:43
Member 1041441717-Jan-17 2:43 
AnswerRe: Communicating with unmanaged DLL Pin
Midi_Mick17-Jan-17 3:19
professionalMidi_Mick17-Jan-17 3:19 
GeneralRe: Communicating with unmanaged DLL Pin
Member 1041441717-Jan-17 4:13
Member 1041441717-Jan-17 4:13 
AnswerRe: Communicating with unmanaged DLL Pin
Bernhard Hiller17-Jan-17 23:26
Bernhard Hiller17-Jan-17 23:26 
QuestionRe: Communicating with unmanaged DLL Pin
Member 1390693510-Jul-18 22:01
Member 1390693510-Jul-18 22:01 
QuestionGlade errors after launching debug Pin
Sascha Manns16-Jan-17 23:18
professionalSascha Manns16-Jan-17 23:18 
AnswerRe: Glade errors after launching debug [Solved] Pin
Sascha Manns17-Jan-17 5:41
professionalSascha Manns17-Jan-17 5:41 
QuestionImplementing Strategy Pattern Pin
Liagapi16-Jan-17 22:20
Liagapi16-Jan-17 22:20 
I'm trying to calculate the area of different shapes using Strategy pattern and below are my code thus far.
C#
public class Shape
{  public string Name{get;set;}
}
public class Circle:Shape
{ public double Radius{get;set;}
  public Circle (string name, double radius)
  {Name = name; Radius = radius;}
}
public class Square:Shape
{ public double Side {get; set;}
  public Square(string name, double side)
  { Name = name; Side = side;}
}
public interface ICalculateAreaStrategy
{   double Calculate(Shape shape);
}
public class CalculateCircleAreaStrategy: ICalculateAreaStrategy
{   double Calculate(Shape shape)
    {
      return Math.Pow(shape.Radius,2)*3.14;
    }
}
public class CalculateSquareAreaStrategy: ICalculateAreaStrategy
{   double Calculate(Shape shape)
    {
       return shape.Side * shape.Side
    }
}
public class CalculateAreaService 
{  readonly ICalculateAreaStrategy calculateAreaStrategy;
   public CalculateAreaService(ICalculateAreaStrategy strategy)
   {
    calculateAreaStrategy = strategy;
   } 
   double CalculateArea(Shape shape)
   {
     return calculateAreaStrategy.Calculate(shape);
   }
}

The reason I'm stuck is I cannot get access to the Circle or Square class from the Shape object passed to the Calculate() method in the CalculateCircleAreaStrategy and CalculateSquareAreaStrategy classes.

modified 17-Jan-17 4:37am.

AnswerRe: Implementing Strategy Pattern Pin
Pete O'Hanlon16-Jan-17 22:46
mvePete O'Hanlon16-Jan-17 22:46 
GeneralRe: Implementing Strategy Pattern Pin
Liagapi16-Jan-17 23:22
Liagapi16-Jan-17 23:22 
GeneralRe: Implementing Strategy Pattern Pin
harold aptroot16-Jan-17 23:05
harold aptroot16-Jan-17 23:05 
GeneralRe: Implementing Strategy Pattern Pin
Liagapi17-Jan-17 2:25
Liagapi17-Jan-17 2:25 
AnswerRe: Implementing Strategy Pattern Pin
F-ES Sitecore16-Jan-17 23:18
professionalF-ES Sitecore16-Jan-17 23:18 
GeneralRe: Implementing Strategy Pattern Pin
Liagapi16-Jan-17 23:28
Liagapi16-Jan-17 23:28 
GeneralRe: Implementing Strategy Pattern Pin
Bernhard Hiller17-Jan-17 23:21
Bernhard Hiller17-Jan-17 23:21 
AnswerRe: Implementing Strategy Pattern Pin
Gerry Schmitz17-Jan-17 5:48
mveGerry Schmitz17-Jan-17 5:48 
QuestionConvert DateTimeOffset to DateTime in Linq To Entities Pin
Kevin Marois16-Jan-17 13:18
professionalKevin Marois16-Jan-17 13:18 
AnswerRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Pete O'Hanlon16-Jan-17 22:52
mvePete O'Hanlon16-Jan-17 22:52 
GeneralRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Kevin Marois17-Jan-17 5:08
professionalKevin Marois17-Jan-17 5:08 
GeneralRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Kevin Marois17-Jan-17 5:54
professionalKevin Marois17-Jan-17 5:54 
GeneralRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Pete O'Hanlon17-Jan-17 5:56
mvePete O'Hanlon17-Jan-17 5:56 
GeneralRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Kevin Marois17-Jan-17 5:57
professionalKevin Marois17-Jan-17 5:57 
AnswerRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Richard Deeming17-Jan-17 2:34
mveRichard Deeming17-Jan-17 2:34 
GeneralRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Kevin Marois17-Jan-17 5:19
professionalKevin Marois17-Jan-17 5:19 
GeneralRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Richard Deeming17-Jan-17 8:29
mveRichard Deeming17-Jan-17 8:29 

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.