Schizoid Man,
No, you can't call normal_dist.normDensity because normDensity is
declared as static. You need to call:
NormalDistiribution.normDensity
A few recommendations. First, follow the public naming conventions for
your public members. normDensity should be NormDensity.
Also, why not use the PI const on the Math class in the System
namespace? It's actually more precise than your definition by one place.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
(E-Mail Removed)
"Schizoid Man" <(E-Mail Removed)> wrote in message
news:ecsqbg$1f4$(E-Mail Removed)...
>I have two classes. The first one called Program contains the Main()
>method.
>
> This class ideally should be able to call a method called normDensity from
> another class NormalDistribution code attached below the first class.
>
> I instantiate the NormalDistribution class as:
> NormalDistribution normal_dist = new NormalDistribution();
>
> So technically, I should be able to call the method
> normal_dist.normDensity from Main(). However, I cannot see this method.
>
> Any ideas?
>
> Thanks in advance.
> Schiz
>
>
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> namespace Distributions
> {
> class Program
> {
>
> static void Main(string[] args)
> {
>
> string tempNumber;
> double inputNumber;
>
> Console.Write("Enter a number: ");
> tempNumber = Console.ReadLine();
> inputNumber = Convert.ToDouble(tempNumber);
>
> Console.Write("The pdf of {0} is {1}", inputNumber, MISSING
> METHOD);
>
> }
> }
> }
>
>
>
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> namespace Distributions
> {
> class NormalDistribution
> {
> NormalDistribution normal_dist = new NormalDistribution();
> const double pi = 3.1415926535897932384;
>
> public static double normDensity(double x)
> {
> return Math.Exp(-0.5 * x * x) / Math.Sqrt(2 * pi);
> }
>
> }
> }