In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the forms of C# type conversion". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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:
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
The following example converts types of different values to string types:
Static void Main (string [] args) {int I = 75; float f = 53.005f; double d = 2345.7652; bool b = true; Console.WriteLine (i.ToString ()); Console.WriteLine (f.ToString ()); Console.WriteLine (d.ToString ()); Console.WriteLine (b.ToString ()) Console.ReadKey ();}
When the above code is compiled and executed, it produces the following results:
75 53.005 2345.7652 True
In C#, we can see three kinds of cast, such as casting to signed 32-bit integers, and we can find the following three ways:
① (int) ()
② Convert.ToInt32 ()
③ int.Parse ()
As conversion character
The as operator works like a cast, except that it never throws an exception, and if the object cannot be converted, the result is null, and the cast throws an exception.
This is the end of the content of "what are the forms of C# type conversion". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.