C # base usage

Source: Internet
Author: User

1. Call the cognominal method in the base class
[Csharp]
Public class Person
{
Protected string ssn = "444-55-6666 ";
Protected string name = "John L. Malgraine ";
 
Public virtual void GetInfo ()
{
Console. WriteLine ("Name: {0}", name );
Console. WriteLine ("SSN: {0}", ssn );
}
}
Class Employee: Person
{
Public string id = "ABC567EFG ";
Public override void GetInfo ()
{
// Calling the base class GetInfo method:
Base. GetInfo ();
Console. WriteLine ("Employee ID: {0}", id );
}
}
 
Class TestClass
{
Static void Main ()
{
Employee E = new Employee ();
E. GetInfo ();
}
}
/*
Output
Name: John L. Malgraine
SSN: 444-55-6666
Employee ID: ABC567EFG
*/

 
2. Call the construction method of the base class
[Csharp]
Ublic class ActionCancelEventArgs: System. ComponentModel. CancelEventArgs
{
Public ActionCancelEventArgs (): this (false ){}
Public ActionCancelEventArgs (bool cancel): this (false, String. Empty ){}
Public ActionCancelEventArgs (bool cancel, string message): base (cancel)
{
This. message = message;
}
Public string Message {get; set ;}
}

Author: luolunz

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.