HomeAbout Me

C# TYPE CONVERSION

By Daniel Nguyen
Published in WPF - CSharp
October 15, 2022
1 min read
C# TYPE CONVERSION

Type conversion is converting one type of data to another type. It is also known as Type Casting. In C#, type casting has two forms:

  • Implicit type conversion - These conversions are performed by C# in a type-safe manner. For example, conversions from smaller to larger integral types and conversions from derived classes to base classes.
  • Explicit type conversion - These conversions are done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
double d = 5673.74;
int i;
// cast double to int.
i = (int)d;
Console.WriteLine(i);
Console.ReadKey();
// 5673
}
}
}
PropertyMethods
ToBooleanConverts a type to a Boolean value, where possible.
ToByteConverts a type to a byte.
ToCharConverts a type to a single Unicode character, where possible.
ToDateTimeConverts a type (integer or string type) to date-time structures.
ToDecimalConverts a floating point or integer type to a decimal type.
ToDoubleConverts a type to a double type.
ToInt16Converts a type to a 16-bit integer.
ToInt32Converts a type to a 32-bit integer.
ToInt64Converts a type to a 64-bit integer.
ToSbyteConverts a type to a signed byte type.
ToSingleConverts a type to a small floating point number.
ToStringConverts a type to a string.
ToTypeConverts a type to a specified type.
ToUInt16Converts a type to an unsigned int type.
ToUInt32Converts a type to an unsigned long type.
ToUInt64Converts a type to an unsigned big integer.

Tags

#CSharp

Share

Previous Article
C# VARIABLES

Related Posts

C# ARRAYS
January 05, 2024
1 min
© 2025, All Rights Reserved.
Powered By

Quick Links

About Me

Legal Stuff

Social Media