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