C# type conversion
Translation results:
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by Ecma and ISO.
C# was developed by Anders Hejlsberg and his team during the development of the .Net framework.
C# is designed for the Common Language Infrastructure (CLI). The CLI consists of executable code and a runtime environment that allows the use of a variety of high-level languages on different computer platforms and architectures.
C# type conversionsyntax
Type conversion is fundamentally type casting, or converting data from one type to another. In C#, type casting comes in two forms:
Implicit type conversions - These conversions are C#'s default conversions that are performed in a safe manner without causing data loss. For example, converting from a small integer type to a large integer type, and from a derived class to a base class.
Explicit type conversion - explicit type conversion, that is, forced type conversion. Explicit conversion requires a cast operator and causes data loss.
C# type conversionexample
namespace TypeConversionApplication{
class ExplicitConversion
{
static void Main(string[] args)
{
double d = 5673.74;
int i;
// 强制转换 double 为 int
i = (int)d;
Console.WriteLine(i);
Console.ReadKey();
}
}}