C# Convert ToBoolean(Int16)

Description

Convert ToBoolean(Int16) converts the value of the specified 16-bit signed integer to an equivalent Boolean value.

Syntax

Convert.ToBoolean(Int16) has the following syntax.


public static bool ToBoolean(
  short value
)

Parameters

Convert.ToBoolean(Int16) has the following parameters.

  • value - The 16-bit signed integer to convert.

Returns

Convert.ToBoolean(Int16) method returns true if value is not zero; otherwise, false.

Example

The following example converts an array of Int16 values to Boolean values.


/*from w w w .  ja v a 2s .  c  o m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    short[] numbers = { Int16.MinValue, -10, -15, 0, 21, 21453, 
                        Int16.MaxValue };
    bool result;
    
    foreach (short number in numbers)
    {
       result = Convert.ToBoolean(number);                                 
       Console.WriteLine("{0,-7:N0}  -->  {1}", number, result);
    }

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version