18. attributes (1)

Source: Internet
Author: User

1st. Methods

Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
User sz = new User ();
Sz. SetName ("Xiao Wang ");
Sz. SetSex ("Ox ");
MessageBox. Show ("name:" + sz. GetName () + "\ r \ n" + "Gender:" + sz. GetSet ());
}
}
Class User
{
Private string m_Name;
Private string m_Sex;
Public string GetName ()
{
Return m_Name;
}
Public void SetName (string Values)
{
M_Name = Values;
}
Public string GetSet ()
{
Return m_Sex;
}
Public void SetSex (string Values)
{
If (Values = "male" | Values = "female ")
{
M_Sex = Values;
}
Else
{
MessageBox. Show ("the name must be male or female '");
}
}

 

}

2nd. Method (using attributes can achieve the same effect)

Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
User sz = new User ();
Sz. Name = "Xiao Wang ";
Sz. Sex = "who ";
MessageBox. Show ("Name:" + sz. Name + "\ r \ n" + "Gender:" + sz. Sex );
}
}
Class User
{
Private string m_Name;
Private string m_Sex;
Public string Name
{
Get
{
Return m_Name;
}
Set
{
M_Name = value;
}
}
Public string Sex
{
Get
{
Return m_Sex;
}
Set
{
If (value = "male" | value = "female ")
{
M_Sex = value;
}
Else
{
MessageBox. Show ("the name must be male or female '");
}
}
}

}

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.