Get the App
SLTechnology News&Howtos  ›  Development  › 

Case Analysis of C# Type conversion

Shulou Source: shulou.com Published: 2022-06-01 02:09:33 09月21日 Update

Most people do not understand the knowledge points of this "C# type conversion case analysis" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this "C# type conversion case analysis" article.

Type conversion is fundamentally type casting, or the conversion of data from one type to another. In C#, there are two forms of type casting:

Implicit type conversions-these conversions are the default conversions of C# in a secure manner and do not result in data loss. For example, convert from a small integer type to a large integer type, and from a derived class to a base class.

Explicit type conversions-explicit type conversions, that is, cast. Explicit conversion requires a cast operator, and a cast can result in data loss.

The following example shows an explicit type conversion:

Namespace TypeConversionApplication

{

Class ExplicitConversion

{

Static void Main (string [] args)

{

Double d = 5673.74

Int i

/ / cast double to int

I = (int) d

Console.WriteLine (I)

Console.ReadKey ()

}

}

}

When the above code is compiled and executed, it produces the following results:

5673 above is about the content of this article "case Analysis of C# Type conversion". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Type caching content instance compulsion case analysis analysis data integer article knowledge article say facet casting security childhood code value most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL Linux Microsoft Huawei