Please study my code segment i have created one single page for
demonstration.

·         Regarding the error - Static member...cannot be accessed with an
instance reference-

You have declared your member methods as static and static methods are only
accesable using class names not class instance.

C my code

Complex complex1 = new Complex(1.1, 1.2);

 Complex complex2 = new Complex(1.1, 1.2);

 Complex complex3;

 complex3=*Complex.add(complex1, complex2);*

 *Complex.print(complex3);*

I have called the add method using class name not variable name.

I have created a new static function print which accepts a class instance
name if you pass it the instance name it will print the associated values.

·         Regarding the error - the type of namespace numa 'sum' could be
found(are you missing a
using directive or an assemby reference?)

I have kept my structure and main method under one namespace. You have to do
the same if you have defined your structure in a separate file please keep
it under same namespace or import the namespace otherwise it will be
unavailable to your main method.



Just create a new console application and paste my provided solution in the
default Program.cs file it will run.


On Fri, Jul 10, 2009 at 1:53 PM, thread <yaniv...@gmail.com> wrote:

> i added this code
>        class MainClass
>         {
>                static void Main(string[] args)
>                {
>                         Complex num1 = new Complex(2,3);
>                        Complex num2 = new Complex(9,4);
>                        Complex sum = new Complex(12,3);
>                        Console.Out.WriteLine("{0}",sum.add(num1,num2));
>                }
>        }
> but i'm getting 2 errors:
> Static member...cannot be accessed with an instance reference-
>
> the type of namespace numa 'sum' could be found(are you missing a
> using directive or an assemby reference?)-
>
>
>
> On 10 יולי, 06:24, Brandon Betances <bbetan...@gmail.com> wrote:
> > What errors are you getting?
> >
> >
> >
> > On Thu, Jul 9, 2009 at 4:42 PM, thread <yaniv...@gmail.com> wrote:
> >
> > > hello all,
> > > i'm trying to use this code in MainClass but nothing works:
> > >        struct Complex
> > >        {
> > >                double r;
> > >                double i;
> > >                public Complex(double rt,double it)
> > >                {
> > >                        r = rt;
> > >                        i = it;
> > >                }
> > >                public static Complex add(Complex a,Complex b)
> > >                {
> > >                        return new Complex(a.r+b.r,a.i+b.i);
> > >                }
> > >                public static Complex sub(Complex a,Complex b)
> > >                {
> > >                        return new Complex(a.r-b.r,a.i-b.i);
> > >                }
> > >                public static Complex mul(Complex a,Complex b)
> > >                {
> > >                        return new Complex(a.r*b.r,a.i*b.i);
> > >                }
> > >        }
> >
> > > does anyone have an idea for it?-הסתר טקסט מצוטט-
> >
> > -הראה טקסט מצוטט-




-- 
Regards
Jay Dan

Reply via email to