2010/03/04

C# week5_3


  1. this
  2. Method overloading

  3. inheritance



  4. this
    class xyz

    {
    public int id;
    xyz ()
    {
    this.id=id; (Access class valuable)
    }
    }

     

  5. Method overloading
    Def. If 2 Methods in a class has a same name, but they have different number of parameter (augment) or same number of parameter but different is their data type called "over load Method".

     
    If 2 methods in a class define with the same name, same number of parameter, same type of parameter, but have different return data type, they will not be overloaded.
    = error (It is required same order.)

     
    namespace ConsoleApplication4
    {
    class abc
    {
    static void Main(string[] arg)
    {
    Test t = new Test();
    Test t1 = new Test(3);
    Test t2 = new Test(3.3);
    }
    }
    class Test
    {
    public Test()
    {
    Console.WriteLine("Without parameter");
    }

     
    public Test(int i)
    {
    Console.WriteLine("one int parameter");
    }

     
    public Test(double k)
    {
    Console.WriteLine("one double parameter");
    }
    }
    }

     
    Result
    Without parameter
    one into parameter
    one double parameter

     

  6. inheritance: reuse
    class A
    {
    protected int i=5;
    protected void xyz();
    }
    class B:A
    {
    (class B can use A)
    }
    class C
    {
    (class C can't use A)
    }

     
    class A
    {
    static protected void xyz()
    {
    Console.WriteLine(" ");
    }
    }
    class B:A
    {
    static void Main
    {
    static xyz();
    }
    }

     

0 件のコメント:

コメントを投稿

UA-9417263-1