1. Home
  2. /
  3. Docs
  4. /
  5. C# Programming
  6. /
  7. Basics
  8. /
  9. Casting

Casting

Implicit Casting

private static void ImplicitCasting()
{
    char c = 'A';
    int i = c;
    long j = i;
    float k = j;
    double l = k;
}

Explicit Casting

private static void ExplicitCasting()
{
    short h = (short)c;
    k = (float)l;
    j = (long)k;
    i = (int)j;
    c = (char)i;
}

Type Conversion Class

private static void TypeConversionClass()
{
    string s = "1";
    i = Convert.ToInt32(s);

    string str = "abc";
    var a = 1;
    // a = Convert.ToInt32("abc"); //not valid (input format exception)
}
Still stuck? Contact

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *

All Rights Reserved 2025.
How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site