DEV Community

Robert Lynch
Robert Lynch

Posted on

Type Conversion.

Type Conversion

:

  • Implicit: byte b = 1; //takes 1 byte of memory
    int i = b; //integer takes 4 bytes
    (you can copy a byte into an int, but not
    an int into a byte). // won't Compile

  • Explicit: float f = 1.0f;
    int i = (int)f;(casting)

  • Conversion between non-compatible types:
    string s = "1";
    int i = Convert.ToInt32(s)
    int j = int.Parse(s);

Convert Methods():Examples

         ToByte() //To convert to a byte
         ToInt16() //To convert to a 16 "Short"
         ToInt32() //To convert to a 32 "int"
         ToInt64() //To convert to a 65 "Long"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay