Dieser Artikel wurde manuell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen.
Übersetzung
Original
Dieser Artikel wurde noch nicht bewertet - Dieses Thema bewerten.

Convert.ToUInt16-Methode (Single)

Konvertiert den Wert der angegebenen Gleitkommazahl mit einfacher Genauigkeit in die entsprechende 16-Bit-Ganzzahl ohne Vorzeichen.

Diese API ist nicht CLS-kompatibel. 

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
[CLSCompliantAttribute(false)]
public static ushort ToUInt16(
	float value
)

Parameter

value
Typ: System.Single
Die zu konvertierende Gleitkommazahl mit einfacher Genauigkeit.

Rückgabewert

Typ: System.UInt16
value, auf die nächste 16-Bit-Ganzzahl ohne Vorzeichen gerundet. Wenn value genau zwischen zwei ganzen Zahlen liegt, wird die gerade Zahl zurückgegeben (d. h. 4,5 wird in 4 und 5,5 in 6 konvertiert).
AusnahmeBedingung
OverflowException

value ist kleiner als 0 (null) oder größer als UInt16.MaxValue.

Das folgende Beispiel wird jedes Element in einem Array von String-Werten in eine 16-Bit-Ganzzahl ohne Vorzeichen konvertiert.


float[] numbers = { Single.MinValue, -1.38e10f, -1023.299f, -12.98f,
                   0f, 9.113e-16f, 103.919f, 17834.191f, Single.MaxValue };
ushort result;

foreach (float number in numbers)
{
   try {
      result = Convert.ToUInt16(number);
      Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.", 
                        number.GetType().Name, number, 
                        result.GetType().Name, result);
   }                     
   catch (OverflowException) {
      Console.WriteLine("{0} is outside the range of the UInt16 type.", number);
   }   
}                                 
// The example displays the following output:
//    -3.402823E+38 is outside the range of the UInt16 type.
//    -1.38E+10 is outside the range of the UInt16 type.
//    -1023.299 is outside the range of the UInt16 type.
//    -12.98 is outside the range of the UInt16 type.
//    Converted the Single value '0' to the UInt16 value 0.
//    Converted the Single value '9.113E-16' to the UInt16 value 0.
//    Converted the Single value '103.919' to the UInt16 value 104.
//    Converted the Single value '17834.19' to the UInt16 value 17834.
//    3.402823E+38 is outside the range of the UInt16 type.


.NET Framework

Unterstützt in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Unterstützt in: 4, 3.5 SP1

Unterstützt in:

Windows 7, Windows Vista SP1 oder höher, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core wird nicht unterstützt), Windows Server 2008 R2 (Server Core wird mit SP1 oder höher unterstützt), Windows Server 2003 SP2

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
Fanden Sie dies hilfreich?
(1500 verbleibende Zeichen)

Community-Beiträge

HINZUFÜGEN
© 2013 Microsoft. Alle Rechte vorbehalten.