15. Class Modifier

Source: Internet
Author: User

1.Class

Namespace _ 15. Class Modifier
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}

 

Private void Form1_Load (object sender, EventArgs e)
{
DefaultMethod ();
PublicMethod ();
PrivateMethod ();
InternalMethod ();
ProtectedMethod ();
ProtectedInternalMethod ();

}
Void defaultMethod ()
{
MessageBox. Show ("This is defaut method ");
}
Public void publicMethod ()
{
MessageBox. Show ("This is public method ");
}
Private void privateMethod ()
{
MessageBox. Show ("This is private method ");
}
Internal void internalMethod ()
{
MessageBox. Show ("This is internal method ");
}
Protected void protectedMethod ()
{
MessageBox. Show ("This is protected method ");
}
Protected internal void protectedInternalMethod ()
{
MessageBox. Show ("This is protectedInternal method ");
}
}
}

2.In the Assembly (Public, internal, Protected interal can be passed)

Namespace _ 15. Class Modifier
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}

 

Private void Form1_Load (object sender, EventArgs e)
{
Mod mod = new Mod ();
// Mod. defaultMethod ();
Mod. publicMethod ();
// Mod. privateMethod ();
Mod. internalMethod ();
// Mod. protectedMethod ();
Mod. protectedInternalMethod ();
}
}
Class Mod
{
Void defaultMethod ()
{
MessageBox. Show ("This is defaut method ");
}
Public void publicMethod ()
{
MessageBox. Show ("This is public method ");
}
Private void privateMethod ()
{
MessageBox. Show ("This is private method ");
}
Internal void internalMethod ()
{
MessageBox. Show ("This is internal method ");
}
Protected void protectedMethod ()
{
MessageBox. Show ("This is protected method ");
}
Protected internal void protectedInternalMethod ()
{
MessageBox. Show ("This is protectedInternal method ");
}
}
}

3.Subclass (public, internal, protected, Protected internal available)

Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}

 

Private void Form1_Load (object sender, EventArgs e)
{
Test test = new Test ();
Test. Run ();
}
}
Class Test: Mod
{
Public void Run ()
{
// DefaultMethod ();
PublicMethod ();
// PrivateMethod ();
InternalMethod ();
ProtectedMethod ();
ProtectedInternalMethod ();
}
}
Class Mod
{
Void defaultMethod ()
{
MessageBox. Show ("This is defaut method ");
}
Public void publicMethod ()
{
MessageBox. Show ("This is public method ");
}
Private void privateMethod ()
{
MessageBox. Show ("This is private method ");
}
Internal void internalMethod ()
{
MessageBox. Show ("This is internal method ");
}
Protected void protectedMethod ()
{
MessageBox. Show ("This is protected method ");
}
Protected internal void protectedInternalMethod ()
{
MessageBox. Show ("This is protectedInternal method ");
}
}

4.Outside the Assembly (public can be passed)

 

 


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.