Property extension and simple review of functions

Source: Internet
Author: User

One, Attribute extension

The use of a private variable can have more than one property, or can return any value type, so that the value type you need to use a function method to write out to achieve their own purposes.

Cases:

Nxinxi class

public class Nxinxi
{
private string _ncd;

public string NCD
{
get {return _NCD;}
set {_NCD = value;}
}
private string _nplace;

public string Nplace
{
get {return _nplace;}
set {_nplace = value;}
}
public string Nationplace
{
Get
{
Nxinxidata ndata = new Nxinxidata ();
String end = Ndata.select (_nplace);
return end;
}
}

}

Nxinxidata class

public class Nxinxidata
{
SqlConnection conn = null;
SqlCommand cmd = null;
Public Nxinxidata ()
{
conn = new SqlConnection ("server=.; Database=data0720;user=sa;pwd=123 ");
CMD = conn. CreateCommand ();
}
public string Select (String NCD)
{
String end = "< no >";
Cmd.commandtext = "Select *from nxinxi where [email protected]";
Cmd. Parameters.clear ();
Cmd. Parameters.Add ("@a", NCD);
Conn. Open ();
SqlDataReader dr = cmd. ExecuteReader ();
if (Dr. HasRows)
{
Dr. Read ();
End = dr["Nplace"]. ToString ();
}
Conn. Close ();
return end;
}
}

Second, function review

1, there is a reference to the anti-
Public data type function name (data type parameter name)
{
return data type;
}

2, there is no anti-
public void function name (data type parameter name)
{

}

3. No reference, no anti-
public void function name ()
{

}

4, no reference and anti-
Public data type function name ()
{

return data type;
}

Property extension and simple review of functions

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.