Data | data type | conversion
Programming in C #, the parameter type is not as tolerant as VB, inevitably to the various types of mutual conversion, such as the data entered in the text control in the calculation must be converted to the corresponding numeric types to be calculated. Usually we can do this in three ways:
1. Force type Conversion
private void TST ()
{
String t_string= "1.4532";
Double T_rtn;
T_rtn=math.cos (double) t_string);
...
}
2, Parse method
Classes with double, string, and so on have a method named Parse, which we can use to convert other types of variables to this type:
private void Button1_Click (object sender, System.EventArgs e)
{
Double sp_x,sp_y,dis,azm,p_x,p_y;
String alpha;string[] aztmp;
Double Ad,am,as; Degrees, minutes, seconds
Alpha=az. Text;
Aztmp=alpha.split ('. ');
Ad=convert.todouble (Aztmp[0]);
Am=convert.todouble (Aztmp[1]. Substring (0,2));
As=convert.todouble (Aztmp[1]. Substring (2,2));
Dbg.text =convert.tostring (Ad) + "" + convert.tostring (Am) + "" +convert.tostring (AS);
Sp_x=double. Parse (SX. Text);
Sp_y=double. Parse (sy. Text);
Dis=double. Parse (D.text);
azm= (ad+am/60.0+as/3600) * MATH.PI/180;
p_x= (Double) System.Math.Cos (AZM) * dis+sp_x;
P_y= (Double) System.Math.Sin (AZM) * DIS+SP_Y;
Px. Text=p_x.tostring ();
Py. Text=p_y.tostring ();
Point3 p3=new Point3 ();
P3.x=1.256;p3.y =2.356;p3.h=100;
Dbg.text=p3. ToString ();
}
3. Convert type
private void Button1_Click (object sender, System.EventArgs e)
{
Double sp_x,sp_y,dis,azm,p_x,p_y;
String alpha;string[] aztmp;
Double Ad,am,as; Degrees, minutes, seconds
Alpha=az. Text;
Aztmp=alpha.split ('. ');
Ad=convert.todouble (Aztmp[0]);
Am=convert.todouble (Aztmp[1]. Substring (0,2));
As=convert.todouble (Aztmp[1]. Substring (2,2));
Dbg.text =convert.tostring (Ad) + "" + convert.tostring (Am) + "" +convert.tostring (AS);
Sp_x=double. Parse (SX. Text);
Sp_y=double. Parse (sy. Text);
Dis=double. Parse (D.text);
azm= (ad+am/60.0+as/3600) * MATH.PI/180;
p_x= (Double) System.Math.Cos (AZM) * dis+sp_x;
P_y= (Double) System.Math.Sin (AZM) * DIS+SP_Y;
Px. Text=p_x.tostring ();
Py. Text=p_y.tostring ();
Point3 p3=new Point3 ();
P3.x=1.256;p3.y =2.356;p3.h=100;
Dbg.text=p3. ToString ();
}