iOS Guides | Samples

Foundation.NSNumber Class

Binding to Objective-C API to box numbers (value types).

See Also: NSNumber

Syntax

[Foundation.Register("NSNumber", true)]
public class NSNumber : NSValue, IComparable, IComparable<NSNumber>, IEquatable<NSNumber>

Remarks

NSNumber provides explicit operator conversions that allow you to cast an NSNumber into any of the core .NET types (float, double, int, uint, short, ushort, byte, sbyte and bool).

NSNumber also provides implicit operator conversions that allow you to create NSNumber instances from the core .NET types (float, double, int, uint, short, ushort, byte, sbyte and bool).

C# Example

// Creates an NSNumber that contains the integer value 4.
NSNumber d = 4;

// Obtains a float from an NSNumber using explicit casts:
float asFloat = (float) d;

// Passes a float to a method taking an NSNumber implicitly:
void RunForSeconds (NSNumber seconds)
{
...
}
[...]
RunForSeconds (4);

Related content

Requirements

Namespace: Foundation
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0

The members of Foundation.NSNumber are listed below.

See Also: NSValue

Public Constructors

Protected Constructors

Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

Public Properties

[read-only]
BoolValueBoolean. Convertthis value into a boolean (0 == false).
[read-only]
ByteValueByte. Converts this value into a byte.
[read-only]
override
ClassHandleIntPtr. The handle for this class.
[read-only]
DoubleValueDouble. Returns this number as a double.
[read-only]
FloatValueSingle. Returns this number as a float.
[read-only]
Int16ValueInt16. Retrieves the value of the number as a short.
[read-only]
Int32ValueInt32. Retrieves the value of the number as an int.
[read-only]
Int64ValueInt64. Retrieves the value of the number as a long.
[read-only]
LongValuenint.
[read-only]
NFloatValuenfloat.
[read-only]
NIntValuenint.
[read-only]
NSDecimalValueNSDecimal. The value of the number as an NSDecimal.
[read-only]
NUIntValuenuint.
[read-only]
SByteValueSByte. The value of the number as an sbyte.
[read-only]
StringValueString. The value of the number formatted as a human-readable string.
[read-only]
UInt16ValueUInt16. The value of the number as a ushort.
[read-only]
UInt32ValueUInt32. The value of the number as a uint.
[read-only]
UInt64ValueUInt64. The value of the number as a ulong.
[read-only]
UnsignedLongValuenuint.

Public Methods

Compare(NSNumber) : nint
Compares this to another number and returns a value indicating whether it is less than, equal, or greater than this.
CompareTo(NSNumber) : Int32
CompareTo(Object) : Int32
DescriptionWithLocale(NSLocale) : String
Returns a localized description of this number.
Equals(NSNumber) : Boolean
override
Equals(Object) : Boolean
static
FromBoolean(Boolean) : NSNumber
Factory method that creates a number from a bool.
static
FromByte(Byte) : NSNumber
Factory method to create a number from a byte.
static
FromDouble(Double) : NSNumber
Factory method to create a number from a double.
static
FromFloat(Single) : NSNumber
Factory method to create a number from a float.
static
FromInt16(Int16) : NSNumber
Factory method to create a number from a short.
static
FromInt32(Int32) : NSNumber
Factory method to create a number from an int.
static
FromInt64(Int64) : NSNumber
Factory method to create a number from a long.
static
FromLong(nint) : NSNumber
static
FromNFloat(nfloat) : NSNumber
static
FromNInt(nint) : NSNumber
static
FromNUInt(nuint) : NSNumber
static
FromSByte(SByte) : NSNumber
Factory method to create a number from an sbyte.
static
FromUInt16(UInt16) : NSNumber
Factory method to create a number from a ushort.
static
FromUInt32(UInt32) : NSNumber
Factory method to create a number from a uint.
static
FromUInt64(UInt64) : NSNumber
Factory method to create a number from a ulong.
static
FromUnsignedLong(nuint) : NSNumber
override
GetHashCode() : Int32
Generates a hash code for the current instance.
override
ToString() : String
Returns a string representation of the value of the current instance.

Public Operators