C #/vB how to define abstract attributes

Source: Internet
Author: User
The abstract attribute declaration does not provide the Implementation of the attribute accessors. It only declares that the class supports attributes, and leaves the accessors implementation to the derived class.
The following example shows how to implement abstract attributes inherited from the base class.

C #

Public abstract class base
{

    // name is a abstract property 
public abstract string Name
{
get;
set;
}

}

public class Child: Base
{
private string m_Name;

//override abstract property
public override double Name
{
get
{
return m_Name;
}
set
{
m_Name = value;
}
}
}

VB.Net

Public MustInherit Class Base

// name is a abstract property
Public MustOverride Name() As String

End Class

Public class Child
Inherits  Base

Private m_Name As String
//override abstract property
public Overrides Property Name() As String
Get
Return m_Name;
End Get
Set
m_Name = value;
End Set
End Property

End Class

When declaring abstract attributes (such as name in this example), specify which attributes are available for accessors and do not implement them.

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.