1: as shown below:
Float F = 1.2;
Decimal d = 1.2;
This Code cannot be compiled, because floating-point constants such as 1.2 are of the double type by default in C #. If you want to assign values as above, you must write the following code:
Float F = 1.2f;
Decimal d = 1.2 m; // note that this is M !!!!
2: how to convert a numeric string into a real numeric variable:
Note: Int. parse () is the same as int32.parse (), because int is essentially the alias of system. int32.
Of course, the most common method is int. parse (); usage is as follows:
=== Example program that uses int.Parse (C#) ===
using System;
class Program
{
static void Main()
{
// Convert string to number.
string text = "500";
int num = int.Parse(text);
Console.WriteLine(num);
}
}
=== Output of the program ===
500
The code float F1 = int. parse (S2); can also be compiled because the compiler automatically converts the int type returned by Int. parse () to float.
A function closely related to int. parse () is: Int. tryparse ();
There is also one: Convert. int32 ();
=== Example program that uses convert. toint32 (C #) ===
Using system;
Class Program
{
Static void main ()
{
// Convert 'text' string to an integer with convert. toint32.
String text = "500 ";
Int num = convert. toint32 (text );
Console. writeline (Num );
}
}
=== Output of the program ===
500
How to convert a basic type to a string is a very simple problem. Each type contains a tostring () method and can be used.
3: in C #, you can perform the modulo operation (remainder) on floating point variables as follows:
Float F1 = 15.6f % 2f;
Console. writeline (F1); // output is 1.6
It should be noted that if the desired result must exist in the float type, the 15.6 must be followed by F. Otherwise, the double type cannot be converted to float during compilation.
4: in C #, ++, -- the operator can act on the floating point type .... If F1 = 1.6; F1 ++; it would be 2.6, huh, well, it should have such a function. In addition, the rules for front ++ and back ++ are the same as those for C ++.