Maha

Maha

  • NA
  • 0
  • 326.5k

NP62 Method call

Nov 25 2007 9:15 PM

Hi Guys

 

NP62   Method call

 

When you call the method, however, the arguments you send to it must match in both number and type with the arguments listed in the method declaration. This is a guide line has to follow in initiating a method call.

 

I got the following program from the website.

http://www.java2s.com/Tutorial/CSharp/0060__Operator/TypeoperatorsIs.htm

 

In the program

 

   Test("Test", new Paper(),

                     new NonPrintablePaper());

 

is calling

 

   Test(string sister, params object[] papers).

 

But it is not meeting the above guide line. Anyone knows please explain the reason.

 

Thank you

 

using System;

 

interface Printable

{

    void print(string name);

}

class Paper : Printable

{

    public void print(string name)

    {

        Console.WriteLine("Poking {0}", name);

    }

}

class NonPrintablePaper

{

}

class MainClass

{

    public static void Test(string sister, params object[] papers)

    {

        foreach (object o in papers)

        {

            if (o is Printable)

            {

                Printable p = (Printable)o;

                p.print(sister);

            }

        }

    }

    public static void Main()

    {

        Test("Test", new Paper(), new NonPrintablePaper());

    }

}

/*

Poking Test

*/


Answers (13)