extends System.Object
| Variables: |
|---|
| Constructors: |
|---|
| Functions: |
|---|
public static System.Boolean ToBoolean(System.Decimal value) Converts a System.Decimal to a System.Boolean. Parameter value: The System.Decimal value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Decimal values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
decimal decimal0 = 0m;
decimal decimal1 = 1m;
decimal decimal2 = -2m;
bool bool0 = Convert.ToBoolean(decimal0);
bool bool1 = Convert.ToBoolean(decimal1);
bool bool2 = Convert.ToBoolean(decimal2);
Console.WriteLine("(decimal) {0} as bool = {1}",decimal0,bool0);
Console.WriteLine("(decimal) {0} as bool = {1}",decimal1,bool1);
Console.WriteLine("(decimal) {0} as bool = {1}",decimal2,bool2);
}
}
The output is (decimal) 0 as bool = False (decimal) 1 as bool = True (decimal) -2 as bool = True |
public static System.Boolean ToBoolean(System.Double value) Converts a System.Double to a System.Boolean . Parameter value: The System.Double value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Double values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
double double0 = 0.0;
double double1 = 1.0;
double double2 = -2.0;
bool bool0 = Convert.ToBoolean(double0);
bool bool1 = Convert.ToBoolean(double1);
bool bool2 = Convert.ToBoolean(double2);
Console.WriteLine("(double) {0} as bool = {1}",double0,bool0);
Console.WriteLine("(double) {0} as bool = {1}",double1,bool1);
Console.WriteLine("(double) {0} as bool = {1}",double2,bool2);
}
}
The output is (double) 0 as bool = False (double) 1 as bool = True (double) -2 as bool = True |
public static System.Boolean ToBoolean(System.Single value) Converts a System.Single to a System.Boolean . Parameter value: The System.Single value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Single values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
float float0 = 0.0f;
float float1 = 1.0f;
float float2 = -2.0f;
bool bool0 = Convert.ToBoolean(float0);
bool bool1 = Convert.ToBoolean(float1);
bool bool2 = Convert.ToBoolean(float2);
Console.WriteLine("(float) {0} as bool = {1}",float0,bool0);
Console.WriteLine("(float) {0} as bool = {1}",float1,bool1);
Console.WriteLine("(float) {0} as bool = {1}",float2,bool2);
}
}
The output is (float) 0 as bool = False (float) 1 as bool = True (float) -2 as bool = True |
public static System.Boolean ToBoolean(System.String value) Converts a System.String to a System.Boolean . Parameter value: The System.String to be converted. Returns: true if value equals System.Boolean.TrueString; false if value equals System.Boolean.FalseString. Throws: : value is a null reference. Throws: : value is not equal to System.Boolean.TrueString or System.Boolean.FalseString. Example: The following example demonstrates converting System.String values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
string string0 = Boolean.TrueString;
string string1 = Boolean.FalseString;
string string2 = "foo"; //This is an invalid Boolean.
bool bool0 = Convert.ToBoolean(string0);
bool bool1 = Convert.ToBoolean(string1);
Console.WriteLine("(string) {0} as bool = {1}",string0,bool0);
Console.WriteLine("(string) {0} as bool = {1}",string1,bool1);
bool bool2 = Convert.ToBoolean(string2); //Throws an exception.
Console.WriteLine("(string) {0} as bool = {1}",string2,bool2);
}
}
The output is
(string) True as bool = True
(string) False as bool = False
Unhandled Exception: System.FormatException: String was not recognized as a valid Boolean.
at System.Boolean.Parse(String value)
at Convert.ToBoolean(String value)
at ConvertBoolTest.Main() in C:\ECMAExamples\ConvertString.cs:line 12
|
public static System.Boolean ToBoolean(System.UInt64 value) Converts a System.UInt64 to a System.Boolean . Parameter value: The 64-bit unsigned integer value to be converted. Returns: true if value is non-zero; false if value is zero. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(System.Decimal). Example: The following example demonstrates converting System.UInt64 values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
ulong ulong0 = 0;
ulong ulong1 = 1;
bool bool0 = Convert.ToBoolean(ulong0);
bool bool1 = Convert.ToBoolean(ulong1);
Console.WriteLine("(ulong) {0} as bool = {1}",ulong0,bool0);
Console.WriteLine("(ulong) {0} as bool = {1}",ulong1,bool1);
}
}
The output is (ulong) 0 as bool = False (ulong) 1 as bool = True |
public static System.Boolean ToBoolean(System.Int64 value) Converts a System.Int64 to a System.Boolean . Parameter value: The 64-bit signed integer value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Int64 values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
long long0 = 0;
long long1 = 1;
long long2 = -2;
bool bool0 = Convert.ToBoolean(long0);
bool bool1 = Convert.ToBoolean(long1);
bool bool2 = Convert.ToBoolean(long2);
Console.WriteLine("(long) {0} as bool = {1}",long0,bool0);
Console.WriteLine("(long) {0} as bool = {1}",long1,bool1);
Console.WriteLine("(long) {0} as bool = {1}",long2,bool2);
}
}
The output is (long) 0 as bool = False (long) 1 as bool = True (long) -2 as bool = True |
public static System.Boolean ToBoolean(System.UInt32 value) Converts a System.UInt32 to a System.Boolean . Parameter value: The 32-bit unsigned integer value to be converted. Returns: true if value is non-zero; false if value is zero. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(System.Int64). Example: The following example demonstrates converting System.UInt32 values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
uint uint0 = 0;
uint uint1 = 1;
bool bool0 = Convert.ToBoolean(uint0);
bool bool1 = Convert.ToBoolean(uint1);
Console.WriteLine("(uint) {0} as bool = {1}",uint0,bool0);
Console.WriteLine("(uint) {0} as bool = {1}",uint1,bool1);
}
}
The output is (uint) 0 as bool = False (uint) 1 as bool = True |
public static System.Boolean ToBoolean(System.Int32 value) Converts a System.Int32 to a System.Boolean . Parameter value: The 32-bit signed integer value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Int32 values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
int int0 = 0;
int int1 = 1;
int int2 = -2;
bool bool0 = Convert.ToBoolean(int0);
bool bool1 = Convert.ToBoolean(int1);
bool bool2 = Convert.ToBoolean(int2);
Console.WriteLine("(int) {0} as bool = {1}",int0,bool0);
Console.WriteLine("(int) {0} as bool = {1}",int1,bool1);
Console.WriteLine("(int) {0} as bool = {1}",int2,bool2);
}
}
The output is (int) 0 as bool = False (int) 1 as bool = True (int) -2 as bool = True |
public static System.Boolean ToBoolean(System.UInt16 value) Converts a System.UInt16 to a System.Boolean . Parameter value: The 16-bit unsigned integer value to be converted. Returns: true if value is non-zero; false if value is zero. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(System.Int32). Example: The following example demonstrates converting System.Int16 values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
ushort ushort0 = 0;
ushort ushort1 = 1;
bool bool0 = Convert.ToBoolean(ushort0);
bool bool1 = Convert.ToBoolean(ushort1);
Console.WriteLine("(ushort) {0} as bool = {1}",ushort0,bool0);
Console.WriteLine("(ushort) {0} as bool = {1}",ushort1,bool1);
}
}
The output is (ushort) 0 as bool = False (ushort) 1 as bool = True |
public static System.Boolean ToBoolean(System.Int16 value) Converts a System.Int16 to a System.Boolean . Parameter value: The 16-bit signed integer value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Byte values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
short short0 = 0;
short short1 = 1;
short short2 = -2;
bool bool0 = Convert.ToBoolean(short0);
bool bool1 = Convert.ToBoolean(short1);
bool bool2 = Convert.ToBoolean(short2);
Console.WriteLine("(short) {0} as bool = {1}",short0,bool0);
Console.WriteLine("(short) {0} as bool = {1}",short1,bool1);
Console.WriteLine("(short) {0} as bool = {1}",short2,bool2);
}
}
The output is (short) 0 as bool = False (short) 1 as bool = True (short) -2 as bool = True |
public static System.Boolean ToBoolean(System.Byte value) Converts a System.Byte to a System.Boolean . Parameter value: The System.Byte value to be converted. Returns: true if value is non-zero; false if value is zero. Example: The following example demonstrates converting System.Byte values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
byte byte0 = (byte) 0;
byte byte1 = (Byte) 1;
bool bool0 = Convert.ToBoolean(byte0);
bool bool1 = Convert.ToBoolean(byte1);
Console.WriteLine("(byte) {0} as bool = {1}",byte0,bool0);
Console.WriteLine("(byte) {0} as bool = {1}",byte1,bool1);
}
}
The output is (byte) 0 as bool = False (byte) 1 as bool = True |
public static System.Boolean ToBoolean(System.SByte value) Converts a System.SByte to a System.Boolean . Parameter value: The 8-bit signed integer value to be converted. Returns: true if value is non-zero; false if value is zero. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToBoolean(System.Object)(System.Int16). Example: The following example demonstrates converting System.SByte values to System.Boolean values. using System;
class ConvertBoolTest {
static public void Main() {
sbyte sbyte0 = (sbyte) 0;
sbyte sbyte1 = (sbyte) 1;
sbyte sbyte2 = (sbyte) -2;
bool bool0 = Convert.ToBoolean(sbyte0);
bool bool1 = Convert.ToBoolean(sbyte1);
bool bool2 = Convert.ToBoolean(sbyte2);
Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte0,bool0);
Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte1,bool1);
Console.WriteLine("(sbyte) {0} as bool = {1}",sbyte2,bool2);
}
}
The output is (sbyte) 0 as bool = False (sbyte) 1 as bool = True (sbyte) -2 as bool = True |
public static System.Boolean ToBoolean(System.Boolean value) Converts a System.Boolean to a System.Boolean . Parameter value: The System.Boolean value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Byte ToByte(System.String value) Converts a System.String representation of a number to a System.Byte . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a System.Byte. Throws: : value is a null reference. Throws: : value does not consist of an optional sign followed by one or more digits (zero through nine). Throws: : The numeric value of value is greater than System.Byte.MaxValue or less than System.Byte.MinValue. Example: The following example demonstrates converting System.String values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
string string0 = "+22";
string string1 = "0";
string string2 = "-1";
byte byte0 = Convert.ToByte(string0);
byte byte1 = Convert.ToByte(string1);
Console.WriteLine("(string) {0} as byte = {1}",string0,byte0);
Console.WriteLine("(string) {0} as byte = {1}",string1,byte1);
byte byte2 = Convert.ToByte(string2);
Console.WriteLine("(string) {0} as byte = {1}",string2,byte2);
}
}
The output is (string) +22 as byte = 22 (string) 0 as byte = 0 Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte. at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider) at System.Byte.Parse(String s) at Convert.ToByte(String value) at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertString.cs:line 11 |
public static System.Byte ToByte(System.Decimal value) Converts a System.Decimal to a System.Byte . Parameter value: The System.Decimal value to be converted. Returns: value as a System.Byte , rounded to the nearest integer. Throws: : value is greater than System.Byte.MaxValue or less than System.Byte.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This process is known as banker's rounding. Example: The following example demonstrates converting System.Decimal values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
decimal decimal0 = 0.0m;
decimal decimal1 = 1.5m;
decimal decimal2 = 2.5m;
decimal decimal3 = -1.0m;
byte byte0 = Convert.ToByte(decimal0);
byte byte1 = Convert.ToByte(decimal1);
byte byte2 = Convert.ToByte(decimal2);
Console.WriteLine("(decimal) {0} as byte = {1}",decimal0,byte0);
Console.WriteLine("(decimal) {0} as byte = {1}",decimal1,byte1);
Console.WriteLine("(decimal) {0} as byte = {1}",decimal2,byte2);
byte byte3 = Convert.ToByte(decimal3); //Throws an exception.
Console.WriteLine("(decimal) {0} as byte = {1}",decimal3,byte3);
}
}
The output is (decimal) 0 as byte = 0 (decimal) 1.5 as byte = 2 (decimal) 2.5 as byte = 2 Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte. at System.Decimal.ToByte(Decimal value) at Convert.ToByte(Decimal value) at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertDecimal.cs:line 15 |
public static System.Byte ToByte(System.Double value) Converts a System.Double to a System.Byte . Parameter value: The System.Double value to be converted. Returns: value as a System.Byte , rounded to the nearest integer. Throws: : value is greater than System.Byte.MaxValue or less than System.Byte.MinValue, or value is equal to one of System.Double.NaN, System.Double.PositiveInfinity, or System.Double.NegativeInfinity. Prior to the conversion, if value is halfway between two numbers, it is rounded to the number that has an even digit in the rightmost decimal position. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36 Example: The following example demonstrates converting System.Double values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
double double0 = 0.0;
double double1 = 1.5;
double double2 = 2.5;
double double3 = -1.0;
byte byte0 = Convert.ToByte(double0);
byte byte1 = Convert.ToByte(double1);
byte byte2 = Convert.ToByte(double2);
Console.WriteLine("(double) {0} as byte = {1}",double0,byte0);
Console.WriteLine("(double) {0} as byte = {1}",double1,byte1);
Console.WriteLine("(double) {0} as byte = {1}",double2,byte2);
byte byte3 = Convert.ToByte(double3); //Throws an exception.
Console.WriteLine("(double) {0} as byte = {1}",double3,byte3);
}
}
The output is (double) 0 as byte = 0 (double) 1.5 as byte = 2 (double) 2.5 as byte = 2 Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte. at Convert.ToByte(Int32 value) at Convert.ToByte(Double value) at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertDouble.cs:line 15 |
public static System.Byte ToByte(System.Single value) Converts a System.Single to a System.Byte . Parameter value: The System.Single value to be converted. Returns: value as a System.Byte , rounded to the nearest integer. Throws: : value is greater than System.Byte.MaxValue or less than System.Byte.MinValue, or value is equal to one of System.Single.NaN, System.Single.PositiveInfinity, or System.Single.NegativeInfinity. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. Example: The following example demonstrates converting System.Single values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
float float0 = 0.0f;
float float1 = 1.5f;
float float2 = 2.5f;
float float3 = -1.0f;
byte byte0 = Convert.ToByte(float0);
byte byte1 = Convert.ToByte(float1);
byte byte2 = Convert.ToByte(float2);
Console.WriteLine("(float) {0} as byte = {1}",float0,byte0);
Console.WriteLine("(float) {0} as byte = {1}",float1,byte1);
Console.WriteLine("(float) {0} as byte = {1}",float2,byte2);
byte byte3 = Convert.ToByte(float3); //Throws an exception.
Console.WriteLine("(float) {0} as byte = {1}",float3,byte3);
}
}
The output is (float) 0 as byte = 0 (float) 1.5 as byte = 2 (float) 2.5 as byte = 2 Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte. at Convert.ToByte(Int32 value) at Convert.ToByte(Single value) at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertFloat.cs:line 15 |
public static System.Byte ToByte(System.UInt64 value) Converts a System.UInt64 to a System.Byte . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a System.Byte. Throws: : value is greater than System.Byte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(System.Decimal). Example: The following example demonstrates converting System.UInt64 values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
ulong ulong0 = 0;
ulong ulong1 = 32000;
byte byte0 = Convert.ToByte(ulong0);
Console.WriteLine("(ulong) {0} as byte = {1}",ulong0,byte0);
byte byte1 = Convert.ToByte(ulong1); //Throws an exception.
Console.WriteLine("(ulong) {0} as byte = {1}",ulong1,byte1);
}
}
The output is (ulong) 0 as byte = 0 Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte. at Convert.ToByte(UInt64 value) at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertUInt64.cs:line 8 |
public static System.Byte ToByte(System.Int64 value) Converts a System.Int64 to a System.Byte . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a System.Byte. Throws: : value is greater than System.Byte.MaxValue or less than System.Byte.MinValue. |
public static System.Byte ToByte(System.UInt32 value) Converts a System.UInt32 to a System.Byte . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a System.Byte. Throws: : value is greater than System.Byte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(System.Int64). |
public static System.Byte ToByte(System.Int32 value) Converts a System.Int32 to a System.Byte . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a System.Byte. Throws: : value is greater than System.Byte.MaxValue or less than System.Byte.MinValue. |
public static System.Byte ToByte(System.UInt16 value) Converts a System.UInt16 to a System.Byte . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a System.Byte. Throws: : value is greater than System.Byte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(System.Int32). Example: The following example demonstrates converting System.UInt16 values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
ushort ushort0 = 0;
ushort ushort1 = 32000;
byte byte0 = Convert.ToByte(ushort0);
Console.WriteLine("(ushort) {0} as byte = {1}",ushort0,byte0);
byte byte1 = Convert.ToByte(ushort1); //Throws an exception.
Console.WriteLine("(ushort) {0} as byte = {1}",ushort1,byte1);
}
}
The output is (ushort) 0 as byte = 0 Exception occurred: System.OverflowException: Value was either too large or too small for an unsigned byte. at Convert.ToByte(UInt16 value) at ConvertByteTest.Main() in C:\ECMAExamples\ConvertToByte\ConvertUInt16.cs:line 8 |
public static System.Byte ToByte(System.Int16 value) Converts a System.Int16 to a System.Byte . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a System.Byte. Throws: : value is greater than System.Byte.MaxValue or less than System.Byte.MinValue. |
public static System.Byte ToByte(System.SByte value) Converts a System.SByte to a System.Byte . Parameter value: The 8-bit signed integer to be converted. Returns: value as a System.Byte. Throws: : value is less than System.Byte.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToByte(System.Object)(System.Int16). |
public static System.Byte ToByte(System.Boolean value) Converts a System.Boolean to a System.Byte . Parameter value: The System.Boolean value to be converted. Returns: If value equals true, returns 1; if value equals false , returns 0. |
public static System.Byte ToByte(System.Byte value) Converts a System.Byte to a System.Byte . Parameter value: The System.Byte value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Byte ToByte(System.Char value) Converts a System.Char to a System.Byte . Parameter value: The Unicode character to be converted interpreted as an unsigned value. Returns: value as a System.Byte. Throws: : The numeric value of value is greater than System.Byte.MaxValue. Example: The following example demonstrates converting System.Char values to System.Byte values. using System;
class ConvertByteTest {
static public void Main() {
char char0 = '0';
char char1 = '1';
char char2 = 'a';
byte byte0 = Convert.ToByte(char0);
byte byte1 = Convert.ToByte(char1);
byte byte2 = Convert.ToByte(char2);
Console.WriteLine("(char) {0} as byte = {1}",char0,byte0);
Console.WriteLine("(char) {0} as byte = {1}",char1,byte1);
Console.WriteLine("(char) {0} as byte = {1}",char2,byte2);
}
}
The output is (char) 0 as byte = 48 (char) 1 as byte = 49 (char) a as byte = 97 |
public static System.Byte ToByte(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Byte . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a System.Byte. Throws: : value is a null reference. Throws: : value does not consist of an optional sign followed by one or more digits (zero through nine). Throws: : The numeric value of value is greater than System.Byte.MaxValue or less than System.Byte.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Char ToChar(System.String value) Converts a System.String to a System.Char . Parameter value: The System.String to be converted. The System.String is required to contain a single character. Returns: value as a System.Char. Throws: : value does not contain exactly one character. |
public static System.Char ToChar(System.UInt64 value) Converts a System.UInt64 to a System.Char . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a System.Char. Throws: : value is greater than System.Char.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToChar(System.Object)(System.Int64). |
public static System.Char ToChar(System.Int64 value) Converts a System.Int64 to a System.Char . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a System.Char. Throws: : value is greater than System.Char.MaxValue or less than System.Char.MinValue. |
public static System.Char ToChar(System.UInt32 value) Converts a System.UInt32 to a System.Char . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a System.Char. Throws: : value is greater than System.Char.MaxValue. |
public static System.Char ToChar(System.Int32 value) Converts a System.Int32 to a System.Char . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a System.Char. Throws: : value is greater than System.Char.MaxValue or less than System.Char.MinValue. |
public static System.Char ToChar(System.UInt16 value) Converts a System.UInt16 to a System.Char . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a System.Char. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToChar(System.Object)(System.Int32). |
public static System.Char ToChar(System.Int16 value) Converts a System.Int16 to a System.Char . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a System.Char. Throws: : value is less than System.Char.MinValue. |
public static System.Char ToChar(System.Byte value) Converts a System.Byte to a System.Char . Parameter value: The System.Byte value to be converted. Returns: value as a System.Char. |
public static System.Char ToChar(System.SByte value) Converts a System.SByte to a System.Char . Parameter value: The System.SByte value to be converted. Returns: value as a System.Char. Throws: : value is less than System.Char.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToChar(System.Object)(System.Int16). |
public static System.Char ToChar(System.Char value) Converts a System.Char to a System.Char . Parameter value: The Unicode character to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.DateTime ToDateTime(System.DateTime value) Converts a System.DateTime to a System.DateTime . Parameter value: The System.DateTime to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.DateTime ToDateTime(System.String value) Converts a System.String to a System.DateTime structure. Parameter value: The System.String to be converted. The string is in a form allowed by the System.DateTime.Parse(System.String)(System.String) method. Returns: value as a System.DateTime. Throws: : value is a null reference. Throws: : value cannot be converted to a System.DateTime . This method parses value using the information in a System.Globalization.DateTimeFormatInfo instance initialized for the current system culture. |
public static System.DateTime ToDateTime(System.String value, System.IFormatProvider provider) Converts a System.String to a System.DateTime structure. Parameter value: The System.String to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.DateTimeFormatInfo containing culture-specific formatting information. Returns: value as a System.DateTime. Throws: : value is a null reference. Throws: : value cannot be converted to a System.DateTime . This method parses value using the information in the System.Globalization.DateTimeFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.DateTimeFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Decimal ToDecimal(System.Boolean value) Converts a System.Boolean to a System.Decimal . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. |
public static System.Decimal ToDecimal(System.Decimal value) Converts a System.Decimal to a System.Decimal . Parameter value: The System.Decimal value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Decimal ToDecimal(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Decimal . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Number style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a System.Decimal. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Decimal ToDecimal(System.String value) Converts a System.String to a System.Decimal . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Number style. Returns: value as a System.Decimal. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. |
public static System.Decimal ToDecimal(System.Double value) Converts a System.Double to a System.Decimal . Parameter value: The System.Double value to be converted. Returns: value as a System.Decimal. The System.Decimal contains 15 significant digits and is rounded using banker's rounding. Throws: : The numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue. |
public static System.Decimal ToDecimal(System.Single value) Converts a System.Single to a System.Decimal . Parameter value: The System.Single value to be converted. Returns: value as a System.Decimal. The System.Decimal contains 7 significant digits and is rounded using banker's rounding. Throws: : The numeric value of value is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue. |
public static System.Decimal ToDecimal(System.UInt64 value) Converts a System.UInt64 to a System.Decimal . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a System.Decimal. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Decimal). |
public static System.Decimal ToDecimal(System.Int64 value) Converts a System.Int64 to a System.Decimal . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a System.Decimal. |
public static System.Decimal ToDecimal(System.UInt32 value) Converts a System.UInt32 to a System.Decimal . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a System.Decimal. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int64). |
public static System.Decimal ToDecimal(System.Int32 value) Converts a System.Int32 to a System.Decimal . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a System.Decimal. |
public static System.Decimal ToDecimal(System.UInt16 value) Converts a System.UInt16 to a System.Decimal . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a System.Decimal. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int32). |
public static System.Decimal ToDecimal(System.Int16 value) Converts a System.Int16 to a System.Decimal . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a System.Decimal. |
public static System.Decimal ToDecimal(System.Byte value) Converts a System.Byte to a System.Decimal . Parameter value: The System.Byte value to be converted. Returns: value as a System.Decimal. |
public static System.Decimal ToDecimal(System.SByte value) Converts a System.SByte to a System.Decimal . Parameter value: The System.SByte value to be converted. Returns: value as a System.Decimal. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int16). |
public static System.Double ToDouble(System.Double value) Converts a System.Double to a System.Double . Parameter value: The System.Double value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Double ToDouble(System.Single value) Converts a System.Single to a System.Double . Parameter value: The System.Single value to be converted. Returns: value as a System.Double. |
public static System.Double ToDouble(System.UInt64 value) Converts a System.UInt64 to a System.Double . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a System.Double. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(System.Decimal). |
public static System.Double ToDouble(System.Int64 value) Converts a System.Int64 to a System.Double . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a System.Double. |
public static System.Double ToDouble(System.UInt32 value) Converts a System.UInt32 to a System.Double . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a System.Double. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(System.Int64). |
public static System.Double ToDouble(System.Int32 value) Converts a System.Int32 to a System.Double . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a System.Double. |
public static System.Double ToDouble(System.UInt16 value) Converts a System.UInt16 to a System.Double . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a System.Double. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(System.Int32). |
public static System.Double ToDouble(System.Int16 value) Converts a System.Int16 to a System.Double . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a System.Double. |
public static System.Double ToDouble(System.Byte value) Converts a System.Byte to a System.Double . Parameter value: The System.Byte value to be converted. Returns: value as a System.Double. |
public static System.Double ToDouble(System.SByte value) Converts a System.SByte to a System.Double . Parameter value: The System.SByte value to be converted. Returns: value as a System.Double. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDouble(System.Object)(System.Int16). |
public static System.Double ToDouble(System.Boolean value) Converts a System.Boolean to a System.Double . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. |
public static System.Double ToDouble(System.Decimal value) Converts a System.Decimal to a System.Double . Parameter value: The System.Decimal value to be converted. Returns: value as a System.Double. value is rounded using banker's rounding. |
public static System.Double ToDouble(System.String value) Converts a System.String to a System.Double . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands style. Returns: value as a System.Double. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Double.MaxValue or less than System.Double.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. |
public static System.Double ToDouble(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Double . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a System.Double. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Double.MaxValue or less than System.Double.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Int16 ToInt16(System.Decimal value) Converts a System.Decimal to a System.Int16 . Parameter value: The System.Decimal value to be converted. Returns: value as a 16-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int16.MaxValue or less than System.Int16.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int16 ToInt16(System.String value) Converts a System.String to a System.Int16 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a 16-bit signed integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Int16.MaxValue or less than System.Int16.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. |
public static System.Int16 ToInt16(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Int16 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a 16-bit signed integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Int16.MaxValue or less than System.Int16.MinValue . This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Int16 ToInt16(System.Double value) Converts a System.Double to a System.Int16 . Parameter value: The System.Double value to be converted. Returns: value as a 16-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int16.MaxValue or less than System.Int16.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int16 ToInt16(System.Single value) Converts a System.Single to a System.Int16 . Parameter value: The System.Single value to be converted. Returns: value as a 16-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int16.MaxValue or less than System.Int16.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int16 ToInt16(System.UInt64 value) Converts a System.UInt64 to a System.Int16 . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a 16-bit signed integer. Throws: : value is greater than System.Int16.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Decimal). |
public static System.Int16 ToInt16(System.Int64 value) Converts a System.Int64 to a System.Int16. Parameter value: The 64-bit signed integer value to be converted. Returns: value as a 16-bit signed integer. Throws: : value is greater than System.Int16.MaxValue or less than System.Int16.MinValue. |
public static System.Int16 ToInt16(System.Int16 value) Converts a System.Int16 to a System.Int16 . Parameter value: The 16-bit signed integer value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Int16 ToInt16(System.UInt32 value) Converts a System.UInt32 to a System.Int16 . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a 16-bit signed integer. Throws: : value is greater than System.Int16.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int64). |
public static System.Int16 ToInt16(System.Int32 value) Converts a System.Int32 to a System.Int16 . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a 16-bit signed integer. Throws: : value is greater than System.Int16.MaxValue or less than System.Int16.MinValue. |
public static System.Int16 ToInt16(System.UInt16 value) Converts a System.UInt16 to a System.Int16 . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a 16-bit signed integer. Throws: : value is greater than System.Int16.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int32). |
public static System.Int16 ToInt16(System.Byte value) Converts a System.Byte to a System.Int16 . Parameter value: The System.Byte value to be converted. Returns: value as a 16-bit signed integer. |
public static System.Int16 ToInt16(System.SByte value) Converts a System.SByte to a System.Int16 . Parameter value: The System.SByte value to be converted. Returns: value as a 16-bit signed integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int16). |
public static System.Int16 ToInt16(System.Char value) Converts a System.Char to a System.Int16 . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a 16-bit signed integer. Throws: : The numeric value of value is greater than System.Int16.MaxValue. |
public static System.Int16 ToInt16(System.Boolean value) Converts a System.Boolean to a System.Int16 . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. |
public static System.Int32 ToInt32(System.Boolean value) Converts a System.Boolean to a System.Int32 . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. |
public static System.Int32 ToInt32(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Int32 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a 32-bit signed integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Int32.MaxValue or less than System.Int32.MinValue . This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Int32 ToInt32(System.String value) Converts a System.String to a System.Int32 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a 32-bit signed integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Int32.MaxValue or less than System.Int32.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. |
public static System.Int32 ToInt32(System.Decimal value) Converts a System.Decimal to a System.Int32 . Parameter value: The System.Decimal value to be converted. Returns: value as a 32-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int32.MaxValue or less than System.Int32.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int32 ToInt32(System.Double value) Converts a System.Double to a System.Int32 . Parameter value: The System.Double value to be converted. Returns: value as a 32-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int32.MaxValue or less than System.Int32.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int32 ToInt32(System.Single value) Converts a System.Single to a System.Int32 . Parameter value: The System.Single value to be converted. Returns: value as a 32-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int32.MaxValue or less than System.Int32.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int32 ToInt32(System.UInt64 value) Converts a System.UInt64 to a System.Int32 . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a 32-bit signed integer. Throws: : value is greater than System.Int32.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Decimal). |
public static System.Int32 ToInt32(System.Int64 value) Converts a System.Int64 to a System.Int32 . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a 32-bit signed integer. Throws: : value is greater than System.Int32.MaxValue or less than System.Int32.MinValue. |
public static System.Int32 ToInt32(System.Int32 value) Converts a System.Int32 to a System.Int32 . Parameter value: The 32-bit signed integer value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Int32 ToInt32(System.UInt32 value) Converts a System.UInt32 to a System.Int32 . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a 32-bit signed integer. Throws: : value is greater than System.Int32.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int64). |
public static System.Int32 ToInt32(System.UInt16 value) Converts a System.UInt16 to a System.Int32 . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a 32-bit signed integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int32). |
public static System.Int32 ToInt32(System.Int16 value) Converts a System.Int16 to a System.Int32 . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a 32-bit signed integer. |
public static System.Int32 ToInt32(System.Byte value) Converts a System.Byte to a System.Int32 . Parameter value: The System.Byte value to be converted. Returns: value as a 32-bit signed integer. |
public static System.Int32 ToInt32(System.SByte value) Converts a System.SByte to a System.Int32 . Parameter value: The System.SByte value to be converted. Returns: value as a 32-bit signed integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int16). |
public static System.Int32 ToInt32(System.Char value) Converts a System.Char to a System.Int32 . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a 32-bit signed integer. |
public static System.Int64 ToInt64(System.Char value) Converts a System.Char to a System.Int64 . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a 64-bit signed integer. |
public static System.Int64 ToInt64(System.Boolean value) Converts a System.Boolean to a System.Int64 . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. |
public static System.Int64 ToInt64(System.SByte value) Converts a System.SByte to a System.Int64 . Parameter value: The System.SByte value to be converted. Returns: value as a 64-bit signed integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int16). |
public static System.Int64 ToInt64(System.Byte value) Converts a System.Byte to a System.Int64 . Parameter value: The System.Byte value to be converted. Returns: value as a 64-bit signed integer. |
public static System.Int64 ToInt64(System.Int16 value) Converts a System.Int16 to a System.Int64 . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a 64-bit signed integer. |
public static System.Int64 ToInt64(System.UInt16 value) Converts a System.UInt16 to a System.Int64 . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a 64-bit signed integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int32). |
public static System.Int64 ToInt64(System.Int32 value) Converts a System.Int32 to a System.Int64 . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a 64-bit signed integer. |
public static System.Int64 ToInt64(System.UInt32 value) Converts a System.UInt32 to a System.Int64 . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a 64-bit signed integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int64). |
public static System.Int64 ToInt64(System.UInt64 value) Converts a System.UInt64 to a System.Int64 . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a 64-bit signed integer. Throws: : value is greater than System.Int64.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Decimal). |
public static System.Int64 ToInt64(System.Int64 value) Converts a System.Int64 to a System.Int64 . Parameter value: The 64-bit signed integer value to be converted. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.Int64 ToInt64(System.Single value) Converts a System.Single to a System.Int64 . Parameter value: The System.Single value to be converted. Returns: value as a 64-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int64.MaxValue or less than System.Int64.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int64 ToInt64(System.Double value) Converts a System.Double to a System.Int64 . Parameter value: The System.Double value to be converted. Returns: value as a 64-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int64.MaxValue or less than System.Int64.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int64 ToInt64(System.Decimal value) Converts a System.Decimal to a System.Int64 . Parameter value: The System.Decimal value to be converted. Returns: value as a 64-bit signed integer. value is rounded prior to conversion. Throws: : value is greater than System.Int64.MaxValue or less than System.Int64.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. |
public static System.Int64 ToInt64(System.String value) Converts a System.String to a System.Int64 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a 64-bit signed integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Int64.MaxValue or less than System.Int64.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. |
public static System.Int64 ToInt64(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Int64 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a 64-bit signed integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Int64.MaxValue or less than System.Int64.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.SByte ToSByte(System.Boolean value) Converts a System.Boolean to a System.SByte . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Boolean). |
public static System.SByte ToSByte(System.SByte value) Converts a System.SByte to a System.SByte . Parameter value: The System.SByte value to be converted. Returns: value is returned unchanged. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int16). This method is provided for completeness. |
public static System.SByte ToSByte(System.Char value) Converts a System.Char to a System.SByte . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a System.SByte. Throws: : The numeric value of value is greater than System.SByte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Char). |
public static System.SByte ToSByte(System.Byte value) Converts a System.Byte to a System.SByte . Parameter value: The System.Byte value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Byte). |
public static System.SByte ToSByte(System.Int16 value) Converts a System.Int16 to a System.SByte . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int16). |
public static System.SByte ToSByte(System.UInt16 value) Converts a System.UInt16 to a System.SByte . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int32). |
public static System.SByte ToSByte(System.Int32 value) Converts a System.Int32 to a System.SByte . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int32). |
public static System.SByte ToSByte(System.UInt32 value) Converts a System.UInt32 to a System.SByte . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int64). |
public static System.SByte ToSByte(System.Int64 value) Converts a System.Int64 to a System.SByte . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Int64). |
public static System.SByte ToSByte(System.UInt64 value) Converts a System.UInt64 to a System.SByte . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a System.SByte. Throws: : value is greater than System.SByte.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Decimal). |
public static System.SByte ToSByte(System.Single value) Converts a System.Single to a System.SByte . Parameter value: The System.Single value to be converted. Returns: value as a System.SByte , rounded to the nearest integer. Throws: : value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Single). |
public static System.SByte ToSByte(System.Double value) Converts a System.Double to a System.SByte . Parameter value: The System.Double value to be converted. Returns: value as a System.SByte , rounded to the nearest integer. Throws: : value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Double). |
public static System.SByte ToSByte(System.Decimal value) Converts a System.Decimal to a System.SByte . Parameter value: The System.Decimal value to be converted. Returns: value as a System.SByte , rounded to the nearest integer. Throws: : value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.Decimal). |
public static System.SByte ToSByte(System.String value) Converts a System.String representation of a number to a System.SByte . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a System.SByte. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value in the specified format. Throws: : The numeric value of value is greater than System.SByte.MaxValue or less than System.SByte.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.String). |
public static System.SByte ToSByte(System.String value, System.IFormatProvider provider) Converts a System.String to a System.SByte . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a System.SByte. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt16(System.Object)(System.String, System.IFormatProvider ). |
public static System.Single ToSingle(System.String value, System.IFormatProvider provider) Converts a System.String to a System.Single . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands style. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: value as a System.Single. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Single.MaxValue or less than System.Single.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. |
public static System.Single ToSingle(System.String value) Converts a System.String to a System.Single . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.AllowThousands style. Returns: value as a System.Single. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.Single.MaxValue or less than System.Single.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. |
public static System.Single ToSingle(System.Decimal value) Converts a System.Decimal to a System.Single . Parameter value: The System.Decimal value to be converted. Returns: value as a System.Single. value is rounded using banker's rounding. |
public static System.Single ToSingle(System.Double value) Converts a System.Double to a System.Single . Parameter value: The System.Double value to be converted. Returns: value as a System.Single. Throws: : value is greater than System.Single.MaxValue or less than System.Single.MinValue. |
public static System.Single ToSingle(System.Single value) Converts a System.Single to a System.Single . Parameter value: The System.Single value to be converted. Returns: value as a System.Single . This method is provided for completeness. |
public static System.Single ToSingle(System.UInt64 value) Converts a System.UInt64 to a System.Single . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a System.Single. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToSingle(System.Object)(System.Decimal). |
public static System.Single ToSingle(System.Int64 value) Converts a System.Int64 to a System.Single . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a System.Single. |
public static System.Single ToSingle(System.UInt32 value) Converts a System.UInt32 to a System.Single . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a System.Single. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToSingle(System.Object)(System.Int64). |
public static System.Single ToSingle(System.Int32 value) Converts a System.Int32 to a System.Single . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a System.Single. |
public static System.Single ToSingle(System.UInt16 value) Converts a System.UInt16 to a System.Single . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a System.Single. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToSingle(System.Object)(System.Int32). |
public static System.Single ToSingle(System.Int16 value) Converts a System.Int16 to a System.Single . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a System.Single. |
public static System.Single ToSingle(System.Byte value) Converts a System.Byte to a System.Single . Parameter value: The System.Byte value to be converted. Returns: value as a System.Single. |
public static System.Single ToSingle(System.SByte value) Converts a System.SByte to a System.Single . Parameter value: The System.SByte value to be converted. Returns: value as a System.Single. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToSingle(System.Object)(System.Int16). |
public static System.Single ToSingle(System.Boolean value) Converts a System.Boolean to a System.Single . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. |
public static System.String ToString(System.UInt32 value, System.IFormatProvider provider) Converts a System.UInt32 to a System.String . Parameter value: The 32-bit unsigned integer value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Int64, System.IFormatProvider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.UInt32.ToString. |
public static System.String ToString(System.Int64 value) Converts a System.Int64 to a System.String . Parameter value: The 64-bit signed integer value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.Int64 value, System.IFormatProvider provider) Converts a System.Int64 to a System.String . Parameter value: The 64-bit signed integer value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Int64.ToString. |
public static System.String ToString(System.UInt64 value) Converts a System.UInt64 to a System.String . Parameter value: The 64-bit unsigned integer value to be converted. Returns: Returns the value returned by value.ToString(). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Decimal). See System.UInt64.ToString. |
public static System.String ToString(System.UInt64 value, System.IFormatProvider provider) Converts a System.UInt64 to a System.String . Parameter value: The 64-bit unsigned integer value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Decimal, System.IFormatProvider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.UInt64.ToString . |
public static System.String ToString(System.Single value) Converts a System.Single to a System.String . Parameter value: The System.Single value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.Single value, System.IFormatProvider provider) Converts a System.Single to a System.String . Parameter value: The System.Single value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Single.ToString. |
public static System.String ToString(System.Double value) Converts a System.Double to a System.String . Parameter value: The System.Double value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.Double value, System.IFormatProvider provider) Converts a System.Double to a System.String . Parameter value: The System.Double value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Double.ToString. |
public static System.String ToString(System.Decimal value) Converts a System.Decimal to a System.String . Parameter value: The System.Decimal value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.Decimal value, System.IFormatProvider provider) Converts a System.Decimal to a System.String . Parameter value: The System.Decimal value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Decimal.ToString. |
public static System.String ToString(System.DateTime value) Converts a System.DateTime value to a System.String . Parameter value: The System.DateTime value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.DateTime value, System.IFormatProvider provider) Converts a System.DateTime value to a System.String . Parameter value: The System.DateTime value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.DateTimeFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.DateTimeFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.DateTimeFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.DateTime.ToString. |
public static System.String ToString(System.UInt32 value) Converts a System.UInt32 to a System.String . Parameter value: The 32-bit unsigned integer value to be converted. Returns: Returns the value returned by value.ToString(). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Int64). See System.UInt32.ToString. |
public static System.String ToString(System.Int32 value, System.IFormatProvider provider) Converts a System.Int32 to a System.String . Parameter value: The 32-bit signed integer value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Int32.ToString . |
public static System.String ToString(System.Int32 value) Converts a System.Int32 to a System.String . Parameter value: The 32-bit signed integer value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.UInt16 value, System.IFormatProvider provider) Converts a System.UInt16 to a System.String . Parameter value: The 16-bit unsigned integer value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Int32, System.IFormatProvider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.UInt16.ToString. |
public static System.String ToString(System.UInt16 value) Converts a System.UInt16 to a System.String . Parameter value: The 16-bit unsigned integer value to be converted. Returns: Returns the value returned by value.ToString(). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Int32). See System.UInt16.ToString. |
public static System.String ToString(System.Int16 value, System.IFormatProvider provider) Converts a System.Int16 to a System.String . Parameter value: The 16-bit signed integer value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Int16.ToString. |
public static System.String ToString(System.Int16 value) Converts a System.Int16 to a System.String . Parameter value: The 16-bit signed integer value to be converted. Returns: Returns the value returned by value.ToString(). |
public static System.String ToString(System.Byte value, System.IFormatProvider provider) Converts a System.Byte to a System.String . Parameter value: The System.Byte value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is formatted in accordance with the current system culture. See System.Byte.ToString. |
public static System.String ToString(System.Byte value) Converts a System.Byte to a System.String . Parameter value: The System.Byte value to be converted. Returns: Returns the value returned by value.ToString(). See System.Byte.ToString. |
public static System.String ToString(System.SByte value, System.IFormatProvider provider) Converts a System.SByte to a System.String . Parameter value: The System.SByte value to be converted. Parameter provider: A System.IFormatProvider that supplies a System.Globalization.NumberFormatInfo containing culture-specific formatting information. Returns: Returns the value returned by value.ToString(provider). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Int16, System.IFormatProvider). This method converts value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider , the string is formatted in accordance with the current system culture. See System.SByte.ToString. |
public static System.String ToString(System.SByte value) Converts a System.SByte to a System.String . Parameter value: The System.SByte value to be converted. Returns: Returns the value returned by value.ToString(). This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToString(System.Object)(System.Int16). See System.SByte.ToString. |
public static System.String ToString(System.Char value) Converts a System.Char to a System.String . Parameter value: The System.Char to be converted. Returns: value as a System.String. |
public static System.String ToString(System.Boolean value) Converts a System.Boolean to a System.String . Parameter value: The System.Boolean value to be converted. Returns: Returns the value returned by value .ToString(). |
public static System.String ToString(System.String value) Returns the specified string. Parameter value: A System.String. Returns: value is returned unchanged. This method is provided for completeness. |
public static System.UInt16 ToUInt16(System.String value, System.IFormatProvider provider) Converts a System.String to a System.UInt16 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: An object that implements the System.IFormatProvider interface and supplies a System.Globalization.NumberFormatInfo instance containing culture-specific formatting information. Returns: value as a 16-bit unsigned integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.String, System.IFormatProvider). |
public static System.UInt16 ToUInt16(System.String value) Converts a System.String to a System.UInt16 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a 16-bit unsigned integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.String). |
public static System.UInt16 ToUInt16(System.Decimal value) Converts a System.Decimal to a System.UInt16 . Parameter value: The System.Decimal value to be converted. Returns: value as a 16-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Decimal). |
public static System.UInt16 ToUInt16(System.Double value) Converts a System.Double to a System.UInt16 . Parameter value: The System.Double value to be converted. Returns: value as a 16-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Double). |
public static System.UInt16 ToUInt16(System.Single value) Converts a System.Single to a System.UInt16 . Parameter value: The System.Single value to be converted. Returns: value as a 16-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Single). |
public static System.UInt16 ToUInt16(System.UInt64 value) Converts a System.UInt64 to a System.UInt16 . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a 16-bit unsigned integer. Throws: : value is greater than System.UInt16.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Decimal). |
public static System.UInt16 ToUInt16(System.Int64 value) Converts a System.Int64 to a System.UInt16 . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a 16-bit unsigned integer. Throws: : value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int64). |
public static System.UInt16 ToUInt16(System.UInt32 value) Converts a System.UInt32 to a System.UInt16 . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a 16-bit unsigned integer. Throws: : value is greater than System.UInt16.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int64). |
public static System.UInt16 ToUInt16(System.UInt16 value) Converts a System.UInt16 to a System.UInt16 . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value is returned unchanged. This method is provided for completeness. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int32). |
public static System.UInt16 ToUInt16(System.Int32 value) Converts a System.Int32 to a System.UInt16 . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a 16-bit unsigned integer. Throws: : value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int32). |
public static System.UInt16 ToUInt16(System.Int16 value) Converts a System.Int16 to a System.UInt16 . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a 16-bit unsigned integer. Throws: : value is less than System.UInt16.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int16). |
public static System.UInt16 ToUInt16(System.Byte value) Converts a System.Byte to a System.UInt16 . Parameter value: The System.Byte value to be converted. Returns: value as a 16-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Byte). |
public static System.UInt16 ToUInt16(System.SByte value) Converts a System.SByte to a System.UInt16 . Parameter value: The System.SByte value to be converted. Returns: value as a 16-bit unsigned integer. Throws: : value is less than System.UInt16.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Int16). |
public static System.UInt16 ToUInt16(System.Char value) Converts a System.Char to a System.UInt16 . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a 16-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Char). |
public static System.UInt16 ToUInt16(System.Boolean value) Converts a System.Boolean to a System.UInt16 . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt32(System.Object)(System.Boolean). |
public static System.UInt32 ToUInt32(System.Boolean value) Converts a System.Boolean to a System.UInt32 . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Boolean). |
public static System.UInt32 ToUInt32(System.Char value) Converts a System.Char to a System.UInt32 . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a 32-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Char). |
public static System.UInt32 ToUInt32(System.SByte value) Converts a System.SByte to a System.UInt32 . Parameter value: The System.SByte value to be converted. Returns: value as a 32-bit unsigned integer. Throws: : value is less than System.UInt32.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int16). |
public static System.UInt32 ToUInt32(System.Byte value) Converts a System.Byte to a System.UInt32 . Parameter value: The System.Byte value to be converted. Returns: value as a 32-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Byte). |
public static System.UInt32 ToUInt32(System.Int16 value) Converts a System.Int16 to a System.UInt32 . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a 32-bit unsigned integer. Throws: : value is less than System.UInt32.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int16). |
public static System.UInt32 ToUInt32(System.UInt16 value) Converts a System.UInt16 to a System.UInt32 . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a 32-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int32). |
public static System.UInt32 ToUInt32(System.Int32 value) Converts a System.Int32 to a System.UInt32 . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a 32-bit unsigned integer. Throws: : value is less than System.UInt32.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int32). |
public static System.UInt32 ToUInt32(System.UInt32 value) Converts a System.UInt32 to a System.UInt32 . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value is returned unchanged. This method is provided for completeness. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int64). |
public static System.UInt32 ToUInt32(System.Int64 value) Converts a System.Int64 to a System.UInt32 . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a 32-bit unsigned integer. Throws: : value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Int64). |
public static System.UInt32 ToUInt32(System.UInt64 value) Converts a System.UInt64 to a System.UInt32 . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value as a 32-bit unsigned integer. Throws: : value is greater than System.UInt32.MaxValue. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Decimal). |
public static System.UInt32 ToUInt32(System.Single value) Converts a System.Single to a System.UInt32 . Parameter value: The System.Single value to be converted. Returns: value as a 32-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Single). |
public static System.UInt32 ToUInt32(System.Double value) Converts a System.Double to a System.UInt32 . Parameter value: The System.Double value to be converted. Returns: value as a 32-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Double). |
public static System.UInt32 ToUInt32(System.Decimal value) Converts a System.Decimal to a System.UInt32 . Parameter value: The System.Decimal value to be converted. Returns: value as a 32-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.Decimal). |
public static System.UInt32 ToUInt32(System.String value) Converts a System.String to a System.UInt32 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a 32-bit unsigned integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.String). |
public static System.UInt32 ToUInt32(System.String value, System.IFormatProvider provider) Converts a System.String to a System.UInt32 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: An object that implements the System.IFormatProvider interface and supplies a System.Globalization.NumberFormatInfo instance containing culture-specific formatting information. Returns: value as an 32-bit unsigned integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToInt64(System.Object)(System.String, System.IFormatProvider ). |
public static System.UInt64 ToUInt64(System.String value, System.IFormatProvider provider) Converts a System.String to a System.UInt64 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Parameter provider: A System.Object that implements the System.IFormatProvider interface and supplies a System.Globalization.NumberFormatInfo instance containing culture-specific formatting information. Returns: value as a 64-bit unsigned integer. Throws: : value is a null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.UInt64.MaxValue or less than System.UInt64.MinValue. This method parses value using the information in the System.Globalization.NumberFormatInfo instance supplied by provider. If provider is null or if a System.Globalization.NumberFormatInfo cannot be obtained from provider, the string is parsed using the formatting information of the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int64, System.IFormatProvider ). |
public static System.UInt64 ToUInt64(System.String value) Converts a System.String to a System.UInt64 . Parameter value: The System.String to be converted. The string is in the System.Globalization.NumberStyles.Integer style. Returns: value as a 64-bit unsigned integer. Throws: : value is null reference. Throws: : value cannot be converted to a numeric value. Throws: : The numeric value of value is greater than System.UInt64.MaxValue or less than System.UInt64.MinValue. This method parses value using the information in a System.Globalization.NumberFormatInfo instance initialized for the current system culture. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.String). |
public static System.UInt64 ToUInt64(System.Decimal value) Converts a System.Decimal to a System.UInt64 . Parameter value: The System.Decimal value to be converted. Returns: value as a 64-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt64.MaxValue or less than System.UInt64.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Decimal). |
public static System.UInt64 ToUInt64(System.Double value) Converts a System.Double to a System.UInt64 . Parameter value: The System.Double value to be converted. Returns: value as a 64-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt64.MaxValue or less than System.UInt64.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Double). |
public static System.UInt64 ToUInt64(System.Single value) Converts a System.Single to a System.UInt64 . Parameter value: The System.Single value to be converted. Returns: value as a 64-bit unsigned integer. value is rounded prior to conversion. Throws: : value is greater than System.UInt64.MaxValue or less than System.UInt64.MinValue. Prior to the conversion, if value is halfway between two whole numbers, it is rounded to the nearest even integer. For example, 4.5 is rounded to 4, and 5.5 is rounded to 6. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Single). |
public static System.UInt64 ToUInt64(System.UInt64 value) Converts a System.UInt64 to a System.UInt64 . Parameter value: The 64-bit unsigned integer value to be converted. Returns: value is returned unchanged. This method is provided for completeness. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Decimal). |
public static System.UInt64 ToUInt64(System.Int64 value) Converts a System.Int64 to a System.UInt64 . Parameter value: The 64-bit signed integer value to be converted. Returns: value as a 64-bit unsigned integer. Throws: : value is less than System.UInt64.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int64). |
public static System.UInt64 ToUInt64(System.UInt32 value) Converts a System.UInt32 to a System.UInt64 . Parameter value: The 32-bit unsigned integer value to be converted. Returns: value as a 64-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int64). |
public static System.UInt64 ToUInt64(System.Int32 value) Converts a System.Int32 to a System.UInt64 . Parameter value: The 32-bit signed integer value to be converted. Returns: value as a 64-bit unsigned integer. Throws: : value is less than System.UInt64.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int32). |
public static System.UInt64 ToUInt64(System.UInt16 value) Converts a System.UInt16 to a System.UInt64 . Parameter value: The 16-bit unsigned integer value to be converted. Returns: value as a 64-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int32). |
public static System.UInt64 ToUInt64(System.Int16 value) Converts a System.Int16 to a System.UInt64 . Parameter value: The 16-bit signed integer value to be converted. Returns: value as a 64-bit unsigned integer. Throws: : value is less than System.UInt64.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int16). |
public static System.UInt64 ToUInt64(System.Byte value) Converts a System.Byte to a System.UInt64 . Parameter value: The System.Byte value to be converted. Returns: value as a 64-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Byte). |
public static System.UInt64 ToUInt64(System.SByte value) Converts a System.SByte to a System.UInt64 . Parameter value: The System.SByte value to be converted. Returns: value as a 64-bit unsigned integer. Throws: : value is less than System.UInt64.MinValue . This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Int16). |
public static System.UInt64 ToUInt64(System.Char value) Converts a System.Char to a System.UInt64 . Parameter value: The System.Char to be converted interpreted as an unsigned value. Returns: value as a 64-bit unsigned integer. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Char). |
public static System.UInt64 ToUInt64(System.Boolean value) Converts a System.Boolean to a System.UInt64 . Parameter value: The System.Boolean value to be converted. Returns: If value is true returns 1; if value is false returns 0. This member is not CLS-compliant. For a CLS-compliant alternative, use System.Convert.ToDecimal(System.Object)(System.Boolean). |
| Functions inherited from System.Object: |
|---|
public virtual System.Boolean Equals(System.Object obj) Determines whether the specified System.Object is equal to the current instance. Parameter obj: The System.Object to compare with the current instance. Returns: true if obj is equal to the current instance; otherwise, false. The statements listed below are required to be true for all implementations of the System.Object.Equals(System.Object) method. In the list, x, y, and z represent non-null object references. See System.Object.GetHashCode for additional required behaviors pertaining to the System.Object.Equals(System.Object) method. Implementations of System.Object.Equals(System.Object) should not throw exceptions. The System.Object.Equals(System.Object) method tests for referential equality , which means that System.Object.Equals(System.Object) returns true if the specified instance of Object and the current instance are the same instance; otherwise, it returns false . An implementation of the System.Object.Equals(System.Object) method is shown in the following C# code: public virtual bool Equals(Object obj) { return this == obj; } For some kinds of objects, it is desirable to have System.Object.Equals(System.Object) test for value equality instead of referential equality. Such implementations of Equals return true if the two objects have the same "value", even if they are not the same instance. The definition of what constitutes an object's "value" is up to the implementer of the type, but it is typically some or all of the data stored in the instance variables of the object. For example, the value of a System.String is based on the characters of the string; the Equals method of the System.String class returns true for any two string instances that contain exactly the same characters in the same order. When the Equals method of a base class provides value equality, an override of Equals in a class derived from that base class should invoke the inherited implementation of Equals . It is recommended (but not required) that types overriding System.Object.Equals(System.Object) also override System.Object.GetHashCode. Hashtables cannot be relied on to work correctly if this recommendation is not followed. If your programming language supports operator overloading, and if you choose to overload the equality operator for a given type, that type should override the Equals method. Such implementations of the Equals method should return the same results as the equality operator. Following this guideline will help ensure that class library code using Equals (such as System.Collections.ArrayList and System.Collections.Hashtable ) behaves in a manner that is consistent with the way the equality operator is used by application code. If you are implementing a value type, you should follow these guidelines: For reference types, the guidelines are as follows: If you implement System.IComparable on a given type, you should override Equals on that type. The System.Object.Equals(System.Object) method is called by methods in collections classes that perform search operations, including the System.Array.IndexOf(System.Array,System.Object) method and the System.Collections.ArrayList.Contains(System.Object) method. Example: Example 1: The following example contains two calls to the default implementation of System.Object.Equals(System.Object) . using System;
class MyClass {
static void Main() {
Object obj1 = new Object();
Object obj2 = new Object();
Console.WriteLine(obj1.Equals(obj2));
obj1 = obj2;
Console.WriteLine(obj1.Equals(obj2));
}
}
The output is False True Example 2: The following example shows a Point class that overrides the System.Object.Equals(System.Object) method to provide value equality and a class Point3D, which is derived from Point . Because Point's override of System.Object.Equals(System.Object) is the first in the inheritance chain to introduce value equality, the Equals method of the base class (which is inherited from System.Object and checks for referential equality) is not invoked. However, Point3D.Equals invokes Point.Equals because Point implements Equals in a manner that provides value equality. using System;
public class Point: object {
int x, y;
public override bool Equals(Object obj) {
//Check for null and compare run-time types.
if (obj == null || GetType() != obj.GetType()) return false;
Point p = (Point)obj;
return (x == p.x) && (y == p.y);
}
public override int GetHashCode() {
return x ^ y;
}
}
class Point3D: Point {
int z;
public override bool Equals(Object obj) {
return base.Equals(obj) && z == ((Point3D)obj).z;
}
public override int GetHashCode() {
return base.GetHashCode() ^ z;
}
}
The Point.Equals method checks that the obj
argument is non-null and that it references an instance of the same type as this
object. If either of those checks fail, the method returns false. The
System.Object.Equals(System.Object) method uses
System.Object.GetType to determine whether
the run-time types of the two objects are identical. (Note that
typeof is not used here because it returns the static type.) If
instead the method had used a check of the form
In Point3D.Equals , the inherited Equals method is invoked before anything else is done; the inherited Equals method checks to see that obj is non-null, that obj is an instance of the same class as this object, and that the inherited instance variables match. Only when the inherited Equals returns true does the method compare the instance variables introduced in the subclass. Specifically, the cast to Point3D is not executed unless obj has been determined to be of type Point3D or a subclass of Point3D . Example 3: In the previous example, operator == (the equality operator) is used to compare the individual instance variables. In some cases, it is appropriate to use the System.Object.Equals(System.Object) method to compare instance variables in an Equals implementation, as shown in the following example: using System;
class Rectangle {
Point a, b;
public override bool Equals(Object obj) {
if (obj == null || GetType() != obj.GetType()) return false;
Rectangle r = (Rectangle)obj;
//Use Equals to compare instance variables
return a.Equals(r.a) && b.Equals(r.b);
}
public override int GetHashCode() {
return a.GetHashCode() ^ b.GetHashCode();
}
}
Example 4: In some languages, such as C#, operator overloading is supported. When a type overloads operator ==, it should also override the System.Object.Equals(System.Object) method to provide the same functionality. This is typically accomplished by writing the Equals method in terms of the overloaded operator ==. For example: using System;
public struct Complex {
double re, im;
public override bool Equals(Object obj) {
return obj is Complex && this == (Complex)obj;
}
public override int GetHashCode() {
return re.GetHashCode() ^ im.GetHashCode();
}
public static bool operator ==(Complex x, Complex y) {
return x.re == y.re && x.im == y.im;
}
public static bool operator !=(Complex x, Complex y) {
return !(x == y);
}
}
Because Complex is a C# struct (a value type), it is known that there will be no subclasses of Complex . Therefore, the System.Object.Equals(System.Object) method need not compare the GetType() results for each object, but can instead use the is operator to check the type of the obj parameter. |
public static System.Boolean Equals(System.Object objA, System.Object objB) Determines whether two object references are equal. Parameter objA: First object to compare. Parameter objB: Second object to compare. Returns: true if one or more of the following statements is true: otherwise returns false. This static method checks for null references before it calls objA.Equals(objB ) and returns false if either objA or objB is null. If the Equals(object obj) implementation throws an exception, this method throws an exception. Example: The following example demonstrates the System.Object.Equals(System.Object) method. using System;
public class MyClass {
public static void Main() {
string s1 = "Tom";
string s2 = "Carol";
Console.WriteLine("Object.Equals(\"{0}\", \"{1}\") => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
Console.WriteLine("Object.Equals(\"{0}\", \"{1}\") => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = null;
s2 = "Tom";
Console.WriteLine("Object.Equals(null, \"{1}\") => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = "Carol";
s2 = null;
Console.WriteLine("Object.Equals(\"{0}\", null) => {2}",
s1, s2, Object.Equals(s1, s2));
s1 = null;
s2 = null;
Console.WriteLine("Object.Equals(null, null) => {2}",
s1, s2, Object.Equals(s1, s2));
}
}
The output is Object.Equals("Tom", "Carol") => False Object.Equals("Tom", "Tom") => True Object.Equals(null, "Tom") => False Object.Equals("Carol", null) => False Object.Equals(null, null) => True |
public System.Void Finalize() Allows a System.Object to perform cleanup operations before the memory allocated for the System.Object is automatically reclaimed. During execution, System.Object.Finalize is automatically called after an object becomes inaccessible, unless the object has been exempted from finalization by a call to System.GC.SuppressFinalize(System.Object). During shutdown of an application domain, System.Object.Finalize is automatically called on objects that are not exempt from finalization, even those that are still accessible. System.Object.Finalize is automatically called only once on a given instance, unless the object is re-registered using a mechanism such as System.GC.ReRegisterForFinalize(System.Object) and System.GC.SuppressFinalize(System.Object) has not been subsequently called. Conforming implementations of the CLI are required to make every effort to ensure that for every object that has not been exempted from finalization, the System.Object.Finalize method is called after the object becomes inaccessible. However, there may be some circumstances under which Finalize is not called. Conforming CLI implementations are required to explicitly specify the conditions under which Finalize is not guaranteed to be called. For example, Finalize might not be guaranteed to be called in the event of equipment failure, power failure, or other catastrophic system failures. In addition to System.GC.ReRegisterForFinalize(System.Object) and System.GC.SuppressFinalize(System.Object), conforming implementations of the CLI are allowed to provide other mechanisms that affect the behavior of System.Object.Finalize . Any mechanisms provided are required to be specified by the CLI implementation. The order in which the Finalize methods of two objects are run is unspecified, even if one object refers to the other. The thread on which Finalize is run is unspecified. Every implementation of System.Object.Finalize in a derived type is required to call its base type's implementation of Finalize . This is the only case in which application code calls System.Object.Finalize . The System.Object.Finalize implementation does nothing. A type should implement Finalize when it uses unmanaged resources such as file handles or database connections that must be released when the managed object that uses them is reclaimed. Because Finalize methods may be invoked in any order (including from multiple threads), synchronization may be necessary if the Finalize method may interact with other objects, whether accessible or not. Furthermore, since the order in which Finalize is called is unspecified, implementers of Finalize (or of destructors implemented through overriding Finalize) must take care to correctly handle references to other objects, as their Finalize method may already have been invoked. In general, referenced objects should not be considered valid during finalization. See the System.IDisposable interface for an alternate means of disposing of resources. For C# developers: Destructors are the C# mechanism for performing cleanup operations. Destructors provide appropriate safeguards, such as automatically calling the base type's destructor. In C# code, System.Object.Finalize cannot be called or overridden. |
public virtual System.Int32 GetHashCode() Generates a hash code for the current instance. Returns: A System.Int32 containing the hash code for the current instance. System.Object.GetHashCode serves as a hash function for a specific type. A hash function is used to quickly generate a number (a hash code) corresponding to the value of an object. Hash functions are used with hashtables. A good hash function algorithm rarely generates hash codes that collide. For more information about hash functions, see The Art of Computer Programming , Vol. 3, by Donald E. Knuth. All implementations of System.Object.GetHashCode are required to ensure that for any two object references x and y, if x.Equals(y) == true, then x.GetHashCode() == y.GetHashCode(). Hash codes generated by System.Object.GetHashCode need not be unique. Implementations of System.Object.GetHashCode are not permitted to throw exceptions. The System.Object.GetHashCode implementation attempts to produce a unique hash code for every object, but the hash codes generated by this method are not guaranteed to be unique. Therefore, System.Object.GetHashCode may generate the same hash code for two different instances. It is recommended (but not required) that types overriding System.Object.GetHashCode also override System.Object.Equals(System.Object) . Hashtables cannot be relied on to work correctly if this recommendation is not followed. Use this method to obtain the hash code of an object. Hash codes should not be persisted (i.e. in a database or file) as they are allowed to change from run to run. Example: Example 1 In some cases, System.Object.GetHashCode is implemented to simply return an integer value. The following example illustrates an implementation of System.Int32.GetHashCode , which returns an integer value: using System;
public struct Int32 {
int value;
//other methods...
public override int GetHashCode() {
return value;
}
}
Example 2 Frequently, a type has multiple data members that can participate in generating the hash code. One way to generate a hash code is to combine these fields using an xor (exclusive or) operation, as shown in the following example: using System;
public struct Point {
int x;
int y;
//other methods
public override int GetHashCode() {
return x ^ y;
}
}
Example 3 The following example illustrates another case where the type's fields are combined using xor (exclusive or) to generate the hash code. Notice that in this example, the fields represent user-defined types, each of which implements System.Object.GetHashCode (and should implement System.Object.Equals(System.Object) as well): using System;
public class SomeType {
public override int GetHashCode() {
return 0;
}
}
public class AnotherType {
public override int GetHashCode() {
return 1;
}
}
public class LastType {
public override int GetHashCode() {
return 2;
}
}
public class MyClass {
SomeType a = new SomeType();
AnotherType b = new AnotherType();
LastType c = new LastType();
public override int GetHashCode () {
return a.GetHashCode() ^ b.GetHashCode() ^ c.GetHashCode();
}
}
Avoid implementing System.Object.GetHashCode in a manner that results in circular references. In other words, if AClass.GetHashCode calls BClass.GetHashCode, it should not be the case that BClass.GetHashCode calls AClass.GetHashCode. Example 4 In some cases, the data member of the class in which you are implementing System.Object.GetHashCode is bigger than a System.Int32. In such cases, you could combine the high order bits of the value with the low order bits using an XOR operation, as shown in the following example: using System;
public struct Int64 {
long value;
//other methods...
public override int GetHashCode() {
return ((int)value ^ (int)(value >> 32));
}
}
|
public System.Type GetType() Gets the type of the current instance. Returns: The instance of System.Type that represents the run-time type (the exact type) of the current instance. For two objects x and y that have identical run-time types, System.Object.ReferenceEquals(System.Object,System.Object)(x.GetType(),y.GetType()) returns true . Example: The following example demonstrates the fact that System.Object.GetType returns the run-time type of the current instance: using System;
public class MyBaseClass: Object {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test {
public static void Main() {
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
}
}
The output is mybase: Type is MyBaseClass myDerived: Type is MyDerivedClass object o = myDerived: Type is MyDerivedClass MyBaseClass b = myDerived: Type is MyDerivedClass |
protected System.Object MemberwiseClone() Creates a shallow copy of the current instance. Returns: A shallow copy of the current instance. The run-time type (the exact type) of the returned object is the same as the run-time type of the object that was copied. System.Object.MemberwiseClone creates a new instance of the same type as the current instance and then copies each of the object's non-static fields in a manner that depends on whether the field is a value type or a reference type. If the field is a value type, a bit-by-bit copy of all the field's bits is performed. If the field is a reference type, only the reference is copied. The algorithm for performing a shallow copy is as follows (in pseudo-code): for each instance field f in this instance if (f is a value type) bitwise copy the field if (f is a reference type) copy the reference end for loop This mechanism is referred to as a shallow copy because it copies rather than clones the non-static fields. Because System.Object.MemberwiseClone implements the above algorithm, for any object, a, the following statements are required to be true: System.Object.MemberwiseClone does not call any of the type's constructors. If System.Object.Equals(System.Object) has been overridden, a.MemberwiseClone().Equals(a) might return false . For an alternate copying mechanism, see System.ICloneable . System.Object.MemberwiseClone is protected (rather than public) to ensure that from verifiable code it is only possible to clone objects of the same class as the one performing the operation (or one of its subclasses). Although cloning an object does not directly open security holes, it does allow an object to be created without running any of its constructors. Since these constructors may establish important invariants, objects created by cloning may not have these invariants established, and this may lead to incorrect program behavior. For example, a constructor might add the new object to a linked list of all objects of this class, and cloning the object would not add the new object to that list -- thus operations that relied on the list to locate all instances would fail to notice the cloned object. By making the method protected, only objects of the same class (or a subclass) can produce a clone and implementers of those classes are (presumably) aware of the appropriate invariants and can arrange for them to be true without necessarily calling a constructor. Example: The following example shows a class called MyClass as well as a representation of the instance of MyClass returned by System.Object.MemberwiseClone . using System;
class MyBaseClass {
public static string CompanyName = "My Company";
public int age;
public string name;
}
class MyDerivedClass: MyBaseClass {
static void Main() {
//Create an instance of MyDerivedClass
//and assign values to its fields.
MyDerivedClass m1 = new MyDerivedClass();
m1.age = 42;
m1.name = "Sam";
//Do a shallow copy of m1
//and assign it to m2.
MyDerivedClass m2 = (MyDerivedClass) m1.MemberwiseClone();
}
}
A graphical representation of m1 and m2 might look like this
+---------------+
| 42 | m1
+---------------+
| +---------|-----------------> "Sam"
+---------------+ /|\
|
+---------------+ |
| 42 | | m2
+---------------+ |
| +--------|---------------------|
+---------------+
|
public static System.Boolean ReferenceEquals(System.Object objA, System.Object objB) Determines whether two object references are identical. Parameter objA: First object to compare. Parameter objB: Second object to compare. Returns: True if a and b refer to the same object or are both null references; otherwise, false. This static method provides a way to compare two objects for reference equality. It does not call any user-defined code, including overrides of System.Object.Equals(System.Object) . Example: using System;
class MyClass {
static void Main() {
object o = null;
object p = null;
object q = new Object();
Console.WriteLine(Object.ReferenceEquals(o, p));
p = q;
Console.WriteLine(Object.ReferenceEquals(p, q));
Console.WriteLine(Object.ReferenceEquals(o, p));
}
}
The output is True True False |
public virtual System.String ToString() Creates and returns a System.String representation of the current instance. Returns: A System.String representation of the current instance. System.Object.ToString returns a string whose content is intended to be understood by humans. Where the object contains culture-sensitive data, the string representation returned by System.Object.ToString takes into account the current system culture. For example, for an instance of the System.Double class whose value is zero, the implementation of System.Double.ToString might return "0.00" or "0,00" depending on the current UI culture. Although there are no exact requirements for the format of the returned string, it should as much as possible reflect the value of the object as perceived by the user. System.Object.ToString is equivalent to calling System.Object.GetType to obtain the System.Type object for the current instance and then returning the result of calling the System.Object.ToString implementation for that type. The value returned includes the full name of the type. It is recommended, but not required, that System.Object.ToString be overridden in a derived class to return values that are meaningful for that type. For example, the base data types, such as System.Int32, implement System.Object.ToString so that it returns the string form of the value the object represents. Subclasses that require more control over the formatting of strings than System.Object.ToString provides should implement System.IFormattable, whose System.Object.ToString method uses the culture of the current thread. Example: The following example outputs the textual description of the value of an object of type System.Object to the console. using System;
class MyClass {
static void Main() {
object o = new object();
Console.WriteLine (o.ToString());
}
}
The output is System.Object |