Convert.ToSingle Yöntem

Tanım

Belirtilen değeri tek duyarlıklı kayan nokta sayısına dönüştürür.

Aşırı Yüklemeler

ToSingle(String, IFormatProvider)

Belirtilen kültüre özgü biçimlendirme bilgilerini kullanarak bir sayının belirtilen dize gösterimini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(SByte)

Belirtilen 8 bit imzalı tamsayı değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Object, IFormatProvider)

Belirtilen kültüre özgü biçimlendirme bilgilerini kullanarak belirtilen nesnenin değerini tek duyarlıklı kayan nokta sayısına dönüştürür.

ToSingle(UInt64)

Belirtilen 64 bit işaretsiz tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(UInt32)

Belirtilen 32 bit işaretsiz tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(String)

Bir sayının belirtilen dize gösterimini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Single)

Belirtilen tek duyarlıklı kayan nokta sayısını döndürür; gerçek dönüştürme gerçekleştirilmemesi.

ToSingle(Object)

Belirtilen nesnenin değerini tek duyarlıklı kayan nokta sayısına dönüştürür.

ToSingle(UInt16)

Belirtilen 16 bit işaretsiz tamsayı değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Int32)

Belirtilen 32 bit imzalı tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Int16)

Belirtilen 16 bit imzalı tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Double)

Belirtilen çift duyarlıklı kayan nokta sayısının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Decimal)

Belirtilen ondalık sayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(DateTime)

Bu yöntemin çağrılması her zaman oluşturur InvalidCastException.

ToSingle(Char)

Bu yöntemin çağrılması her zaman oluşturur InvalidCastException.

ToSingle(Byte)

Belirtilen 8 bit işaretsiz tamsayı değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(Boolean)

Belirtilen Boole değerini eşdeğer tek duyarlıklı kayan nokta sayısına dönüştürür.

ToSingle(Int64)

Belirtilen 64 bit imzalı tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

ToSingle(String, IFormatProvider)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen kültüre özgü biçimlendirme bilgilerini kullanarak bir sayının belirtilen dize gösterimini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (string value, IFormatProvider provider);
C#
public static float ToSingle (string? value, IFormatProvider? provider);

Parametreler

value
String

Dönüştürülecek sayıyı içeren bir dize.

provider
IFormatProvider

Kültüre özgü biçimlendirme bilgileri sağlayan nesne.

Döndürülenler

içindeki sayıya eşdeğer tek duyarlıklı kayan noktalı sayı valueveya ise valuenull0 (sıfır)

Özel durumlar

value geçerli biçimde bir sayı değildir.

value , Single.MinValue değerinden küçük veya Single.MaxValue değerinden büyük bir sayıyı temsil eder.

Örnekler

Aşağıdaki örnek, sayısal dize dizisindeki öğeleri değerlere dönüştürdüğünde en-US ve fr-FR kültürlerini Single temsil eden nesneleri kullanırIFormatProvider.

C#
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values = { "123456789", "12345.6789", "12 345,6789",
                          "123,456.789", "123 456,789", "123,456,789.0123",
                          "123 456 789,0123", "1.235e12", "1.03221e-05",
                          Double.MaxValue.ToString() };
      CultureInfo[] cultures = { new CultureInfo("en-US"),
                                 new CultureInfo("fr-FR") };

      foreach (CultureInfo culture in cultures)
      {
         Console.WriteLine("String -> Single Conversion Using the {0} Culture",
                           culture.Name);
         foreach (string value in values)
         {
            Console.Write("{0,22}  ->  ", value);
            try {
               Console.WriteLine(Convert.ToSingle(value, culture));
            }
            catch (FormatException) {
               Console.WriteLine("FormatException");
            }
            catch (OverflowException) {
               Console.WriteLine("OverflowException");
            }
         }
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//    String -> Single Conversion Using the en-US Culture
//                 123456789  ->  1.234568E+08
//                12345.6789  ->  12345.68
//               12 345,6789  ->  FormatException
//               123,456.789  ->  123456.8
//               123 456,789  ->  FormatException
//          123,456,789.0123  ->  1.234568E+08
//          123 456 789,0123  ->  FormatException
//                  1.235e12  ->  1.235E+12
//               1.03221e-05  ->  1.03221E-05
//     1.79769313486232E+308  ->  Overflow
//
//    String -> Single Conversion Using the fr-FR Culture
//                 123456789  ->  1.234568E+08
//                12345.6789  ->  FormatException
//               12 345,6789  ->  12345.68
//               123,456.789  ->  FormatException
//               123 456,789  ->  123456.8
//          123,456,789.0123  ->  FormatException
//          123 456 789,0123  ->  1.234568E+08
//                  1.235e12  ->  FormatException
//               1.03221e-05  ->  FormatException
//     1.79769313486232E+308  ->  FormatException

Açıklamalar

Dönüş değeri, üzerinde valueyöntemini çağırmanın Single.Parse sonucudur.

provider bir nesnesi elde eden bir IFormatProviderNumberFormatInfo örnektir. NumberFormatInfo nesnesi, biçimi valuehakkında kültüre özgü bilgiler sağlar. ise providernull, NumberFormatInfo geçerli kültür için kullanılır.

Dönüştürme başarısız olursa bir özel durumu işlemeyi tercih ederseniz, bunun yerine yöntemini çağırabilirsiniz Single.TryParse . Dönüştürmenin başarılı mı yoksa başarısız mı olduğunu gösteren bir Boolean değer döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(SByte)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 8 bit imzalı tamsayı değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
[System.CLSCompliant(false)]
public static float ToSingle (sbyte value);

Parametreler

value
SByte

Dönüştürülecek 8 bit imzalı tamsayı.

Döndürülenler

ile eşdeğer value8 bit imzalı tamsayı.

Öznitelikler

Örnekler

Aşağıdaki örnek, imzalı bayt dizisindeki her öğeyi bir Single değere dönüştürür.

C#
sbyte[] numbers = { SByte.MinValue, -23, 0, 17, SByte.MaxValue };
float result;

foreach (sbyte number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the SByte value '-128' to the Single value -128.
//    Converted the SByte value '-23' to the Single value -23.
//    Converted the SByte value '0' to the Single value 0.
//    Converted the SByte value '17' to the Single value 17.
//    Converted the SByte value '127' to the Single value 127.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Object, IFormatProvider)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen kültüre özgü biçimlendirme bilgilerini kullanarak belirtilen nesnenin değerini tek duyarlıklı kayan nokta sayısına dönüştürür.

C#
public static float ToSingle (object value, IFormatProvider provider);
C#
public static float ToSingle (object? value, IFormatProvider? provider);

Parametreler

value
Object

Arabirimini uygulayan IConvertible bir nesne.

provider
IFormatProvider

Kültüre özgü biçimlendirme bilgileri sağlayan nesne.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı veya ise value sıfır.null

Özel durumlar

value uygun bir biçimde değil.

value , Single.MinValue değerinden küçük veya Single.MaxValue değerinden büyük bir sayıyı temsil eder.

Örnekler

Aşağıdaki örnek, arabirimini uygulayan IConvertible bir Temperature sınıfı tanımlar. yönteminin IConvertible.ToSingle uygulanması, sıcaklığı temsil eden özel Single bir değişkenin iç değerini döndürür.

C#
using System;
using System.Globalization;

public class Temperature : IConvertible
{
   private float m_Temp;

   public Temperature(float temperature)
   {
      this.m_Temp = temperature;
   }

   public float Celsius
   {
      get { return this.m_Temp; }
   }

   public float Kelvin
   {
      get { return this.m_Temp + 273.15f; }
   }

   public float Fahrenheit
   {
      get { return (float) Math.Round(this.m_Temp * 9 / 5 + 32, 2); }
   }

   public override string ToString()
   {
      return m_Temp.ToString("N2") + " °C";
   }

   // IConvertible implementations.
   public TypeCode GetTypeCode()
   {
      return TypeCode.Object;
   }

   public bool ToBoolean(IFormatProvider provider)
   {
      if (m_Temp == 0)
         return false;
      else
         return true;
   }

   public byte ToByte(IFormatProvider provider)
   {
      if (m_Temp < Byte.MinValue || m_Temp > Byte.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the Byte type.",
                                                   this.m_Temp));
      else
         return Convert.ToByte(this.m_Temp);
   }

   public char ToChar(IFormatProvider provider)
   {
      throw new InvalidCastException("Temperature to Char conversion is not supported.");
   }

   public DateTime ToDateTime(IFormatProvider provider)
   {
      throw new InvalidCastException("Temperature to DateTime conversion is not supported.");
   }

   public decimal ToDecimal(IFormatProvider provider)
   {
      return Convert.ToDecimal(this.m_Temp);
   }

   public double ToDouble(IFormatProvider provider)
   {
      return Convert.ToDouble(this.m_Temp);
   }

   public short ToInt16(IFormatProvider provider)
   {
      if (this.m_Temp < Int16.MinValue || this.m_Temp > Int16.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the Int16 type.",
                                                   this.m_Temp));
      else
         return Convert.ToInt16(this.m_Temp);
   }

   public int ToInt32(IFormatProvider provider)
      {
      if (this.m_Temp < Int32.MinValue || this.m_Temp > Int32.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the Int32 type.",
                                                   this.m_Temp));
      else
         return Convert.ToInt32(this.m_Temp);
   }

   public long ToInt64(IFormatProvider provider)
   {
      if (this.m_Temp < Int64.MinValue || this.m_Temp > Int64.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the Int64 type.",
                                                   this.m_Temp));
      else
         return Convert.ToInt64(this.m_Temp);
   }

   public sbyte ToSByte(IFormatProvider provider)
   {
      if (this.m_Temp < SByte.MinValue || this.m_Temp > SByte.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the SByte type.",
                                                   this.m_Temp));
      else
         return Convert.ToSByte(this.m_Temp);
   }

   public float ToSingle(IFormatProvider provider)
   {
      return this.m_Temp;
   }

   public string ToString(IFormatProvider provider)
   {
      return m_Temp.ToString("N2", provider) + " °C";
   }

   public object ToType(Type conversionType, IFormatProvider provider)
   {
      switch (Type.GetTypeCode(conversionType))
      {
         case TypeCode.Boolean:
            return this.ToBoolean(null);
         case TypeCode.Byte:
            return this.ToByte(null);
         case TypeCode.Char:
            return this.ToChar(null);
         case TypeCode.DateTime:
            return this.ToDateTime(null);
         case TypeCode.Decimal:
            return this.ToDecimal(null);
         case TypeCode.Double:
            return this.ToDouble(null);
         case TypeCode.Int16:
            return this.ToInt16(null);
         case TypeCode.Int32:
            return this.ToInt32(null);
         case TypeCode.Int64:
            return this.ToInt64(null);
         case TypeCode.Object:
            if (typeof(Temperature).Equals(conversionType))
               return this;
            else
               throw new InvalidCastException(String.Format("Conversion to a {0} is not supported.",
                                                            conversionType.Name));
         case TypeCode.SByte:
            return this.ToSByte(null);
         case TypeCode.Single:
            return this.ToSingle(null);
         case TypeCode.String:
            return this.ToString(provider);
         case TypeCode.UInt16:
            return this.ToUInt16(null);
         case TypeCode.UInt32:
            return this.ToUInt32(null);
         case TypeCode.UInt64:
            return this.ToUInt64(null);
         default:
            throw new InvalidCastException(String.Format("Conversion to {0} is not supported.", conversionType.Name));
      }
   }

   public ushort ToUInt16(IFormatProvider provider)
   {
      if (this.m_Temp < UInt16.MinValue || this.m_Temp > UInt16.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the UInt16 type.",
                                                   this.m_Temp));
      else
         return Convert.ToUInt16(this.m_Temp);
   }

   public uint ToUInt32(IFormatProvider provider)
   {
      if (this.m_Temp < UInt32.MinValue || this.m_Temp > UInt32.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the UInt32 type.",
                                                   this.m_Temp));
      else
         return Convert.ToUInt32(this.m_Temp);
   }

   public ulong ToUInt64(IFormatProvider provider)
   {
      if (this.m_Temp < UInt64.MinValue || this.m_Temp > UInt64.MaxValue)
         throw new OverflowException(String.Format("{0} is out of range of the UInt64 type.",
                                                   this.m_Temp));
      else
         return Convert.ToUInt64(this.m_Temp);
   }
}

Aşağıdaki örnekte yöntemine yapılan çağrının Convert.ToSingle(Object, IFormatProvider) da sınıfın IConvertible.ToSingle uygulamasını nasıl çağıracakları gösterilmektedir Temperature .

C#
public class Example
{
   public static void Main()
   {
      Temperature cold = new Temperature(-40);
      Temperature freezing = new Temperature(0);
      Temperature boiling = new Temperature(100);

      Console.WriteLine(Convert.ToInt32(cold, null));
      Console.WriteLine(Convert.ToInt32(freezing, null));
      Console.WriteLine(Convert.ToDouble(boiling, null));
   }
}
// The example dosplays the following output:
//       -40
//       0
//       100

Açıklamalar

Dönüş değeri, temel türündeki IConvertible.ToSingle yöntemini çağırmanın sonucudur value.

provider kullanıcının içeriği hakkında kültüre özgü dönüştürme bilgilerini belirtmesini valuesağlar. Örneğin, bir sayıyı temsil eden bir String isevalue, provider bu sayıyı temsil etmek için kullanılan gösterimi hakkında kültüre özgü bilgiler sağlayabilir.

Temel türler yoksayarprovider; ancak arabirimi uygulayan IConvertible kullanıcı tanımlı bir türse value parametresi kullanılabilir.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(UInt64)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 64 bit işaretsiz tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
[System.CLSCompliant(false)]
public static float ToSingle (ulong value);

Parametreler

value
UInt64

Dönüştürülecek 64 bit işaretsiz tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Öznitelikler

Örnekler

Aşağıdaki örnek, işaretsiz uzun tamsayılar dizisindeki her öğeyi bir Single değere dönüştürür.

C#
ulong[] numbers = { UInt64.MinValue, 121, 12345, UInt64.MaxValue };
float result;

foreach (ulong number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the UInt64 value '0' to the Single value 0.
//    Converted the UInt64 value '121' to the Single value 121.
//    Converted the UInt64 value '12345' to the Single value 12345.
//    Converted the UInt64 value '18446744073709551615' to the Single value 1.844674E+19.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(UInt32)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 32 bit işaretsiz tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
[System.CLSCompliant(false)]
public static float ToSingle (uint value);

Parametreler

value
UInt32

Dönüştürülecek 32 bit işaretsiz tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Öznitelikler

Örnekler

Aşağıdaki örnek, işaretsiz tamsayılar dizisindeki her öğeyi bir Single değere dönüştürür.

C#
uint[] numbers = { UInt32.MinValue, 121, 12345, UInt32.MaxValue };
float result;

foreach (uint number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the UInt32 value '0' to the Single value 0.
//    Converted the UInt32 value '121' to the Single value 121.
//    Converted the UInt32 value '12345' to the Single value 12345.
//    Converted the UInt32 value '4294967295' to the Single value 4.294967E+09.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(String)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Bir sayının belirtilen dize gösterimini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (string value);
C#
public static float ToSingle (string? value);

Parametreler

value
String

Dönüştürülecek sayıyı içeren bir dize.

Döndürülenler

içindeki sayıya eşdeğer tek duyarlıklı kayan noktalı sayı valueveya ise valuenull0 (sıfır)

Özel durumlar

value geçerli biçimde bir sayı değildir.

value , Single.MinValue değerinden küçük veya Single.MaxValue değerinden büyük bir sayıyı temsil eder.

Örnekler

Aşağıdaki örnek, sayısal dize dizisindeki her öğeyi bir Single değere dönüştürmeyi dener.

C#
string[] values= { "-1,035.77219", "1AFF", "1e-35", "1.63f",
                   "1,635,592,999,999,999,999,999,999", "-17.455",
                   "190.34001", "1.29e325"};
float result;

foreach (string value in values)
{
   try {
      result = Convert.ToSingle(value);
      Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                        value.GetType().Name, value,
                        result.GetType().Name, result);
   }
   catch (FormatException) {
      Console.WriteLine("Unable to convert '{0}' to a Single.", value);
   }
   catch (OverflowException) {
      Console.WriteLine("'{0}' is outside the range of a Single.", value);
   }
}
// The example displays the following output:
//    Converted the String value '-1,035.77219' to the Single value -1035.772.
//    Unable to convert '1AFF' to a Single.
//    Converted the String value '1e-35' to the Single value 1E-35.
//    Unable to convert '1.63f' to a Single.
//    Converted the String value '1,635,592,999,999,999,999,999,999' to the Single value 1.635593E+24.
//    Converted the String value '-17.455' to the Single value -17.455.
//    Converted the String value '190.34001' to the Single value 190.34.
//    1.29e325' is outside the range of a Single.

Açıklamalar

yönteminin ToSingle(String) kullanılması yöntemine geçirmekle valueSingle.Parse(String) eşdeğerdir. value geçerli kültürün biçimlendirme kuralları kullanılarak yorumlanır.

Dönüştürme başarısız olursa bir özel durumu işlemeyi tercih ederseniz, bunun yerine yöntemini çağırabilirsiniz Single.TryParse . Dönüştürmenin başarılı mı yoksa başarısız mı olduğunu gösteren bir Boolean değer döndürür.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Single)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen tek duyarlıklı kayan nokta sayısını döndürür; gerçek dönüştürme gerçekleştirilmemesi.

C#
public static float ToSingle (float value);

Parametreler

value
Single

Döndürülecek tek duyarlıklı kayan nokta sayısı.

Döndürülenler

value değişmeden döndürülür.

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Object)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen nesnenin değerini tek duyarlıklı kayan nokta sayısına dönüştürür.

C#
public static float ToSingle (object value);
C#
public static float ToSingle (object? value);

Parametreler

value
Object

arabirimini IConvertiblenullveya uygulayan bir nesne.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı veya ise value sıfır.null

Özel durumlar

value uygun bir biçimde değil.

value arabirimini IConvertible uygulamaz.

-veya-

Dönüşüm desteklenmiyor.

value , Single.MinValue değerinden küçük veya Single.MaxValue değerinden büyük bir sayıyı temsil eder.

Örnekler

Aşağıdaki örnek, bir nesne dizisindeki her öğeyi bir Single değere dönüştürmeyi dener.

C#
object[] values = { true, 'a', 123, 1.764e32, "9.78", "1e-02",
                    1.67e03, "A100", "1,033.67", DateTime.Now,
                    Decimal.MaxValue };
float result;

foreach (object value in values)
{
   try {
      result = Convert.ToSingle(value);
      Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                        value.GetType().Name, value,
                        result.GetType().Name, result);
   }
   catch (FormatException) {
      Console.WriteLine("The {0} value {1} is not recognized as a valid Single value.",
                        value.GetType().Name, value);
   }
   catch (OverflowException) {
      Console.WriteLine("The {0} value {1} is outside the range of the Single type.",
                        value.GetType().Name, value);
   }
   catch (InvalidCastException) {
      Console.WriteLine("Conversion of the {0} value {1} to a Single is not supported.",
                        value.GetType().Name, value);
   }
}
// The example displays the following output:
//    Converted the Boolean value 'True' to the Single value 1.
//    Conversion of the Char value a to a Single is not supported.
//    Converted the Int32 value '123' to the Single value 123.
//    Converted the Double value '1.764E+32' to the Single value 1.764E+32.
//    Converted the String value '9.78' to the Single value 9.78.
//    Converted the String value '1e-02' to the Single value 0.01.
//    Converted the Double value '1670' to the Single value 1670.
//    The String value A100 is not recognized as a valid Single value.
//    Converted the String value '1,033.67' to the Single value 1033.67.
//    Conversion of the DateTime value 11/7/2008 08:02:35 AM to a Single is not supported.
//    Converted the Decimal value '79228162514264337593543950335' to the Single value 7.922816E+28.

Açıklamalar

Dönüş değeri, temel türündeki IConvertible.ToSingle yöntemini çağırmanın sonucudur value.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(UInt16)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Önemli

Bu API, CLS uyumlu değildir.

Belirtilen 16 bit işaretsiz tamsayı değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
[System.CLSCompliant(false)]
public static float ToSingle (ushort value);

Parametreler

value
UInt16

Dönüştürülecek 16 bitlik işaretsiz tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Öznitelikler

Örnekler

Aşağıdaki örnek, işaretsiz 16 bit tamsayı dizisindeki her öğeyi bir Single değere dönüştürür.

C#
ushort[] numbers = { UInt16.MinValue, 121, 12345, UInt16.MaxValue };
float result;

foreach (ushort number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the UInt16 value '0' to the Single value 0.
//    Converted the UInt16 value '121' to the Single value 121.
//    Converted the UInt16 value '12345' to the Single value 12345.
//    Converted the UInt16 value '65535' to the Single value 65535.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Int32)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen 32 bit imzalı tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (int value);

Parametreler

value
Int32

Dönüştürülecek 32 bit imzalı tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Örnekler

Aşağıdaki örnek, bir tamsayı dizisindeki her öğeyi bir Single değere dönüştürür.

C#
int[] numbers = { Int32.MinValue, -1000, 0, 1000, Int32.MaxValue };
float result;

foreach (int number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the Int32 value '-2147483648' to the Single value -2.147484E+09.
//    Converted the Int32 value '-1000' to the Single value -1000.
//    Converted the Int32 value '0' to the Single value 0.
//    Converted the Int32 value '1000' to the Single value 1000.
//    Converted the Int32 value '2147483647' to the Single value 2.147484E+09.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Int16)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen 16 bit imzalı tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (short value);

Parametreler

value
Int16

Dönüştürülecek 16 bitlik işaretli tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Örnekler

Aşağıdaki örnek, 16 bit tamsayı dizisindeki her öğeyi bir Single değere dönüştürür.

C#
short[] numbers = { Int16.MinValue, -1032, 0, 192, Int16.MaxValue };
float result;

foreach (short number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the Int16 value '-32768' to the Single value -32768.
//    Converted the Int16 value '-1032' to the Single value -1032.
//    Converted the Int16 value '0' to the Single value 0.
//    Converted the Int16 value '192' to the Single value 192.
//    Converted the Int16 value '32767' to the Single value 32767.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Double)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen çift duyarlıklı kayan nokta sayısının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (double value);

Parametreler

value
Double

Dönüştürülecek çift duyarlıklı kayan nokta sayısı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

value , yuvarlama kullanılarak en yakına yuvarlanır. Örneğin, iki ondalık basameğe yuvarlandığında, 2,345 değeri 2,34 olur ve 2,355 değeri 2,36 olur.

Örnekler

Aşağıdaki örnek, bir değer dizisindeki Double her öğeyi bir Single değere dönüştürür.

C#
double[] values = { Double.MinValue, -1.38e10, -1023.299, -12.98,
                    0, 9.113e-16, 103.919, 17834.191, Double.MaxValue };
float result;

foreach (double value in values)
{
   result = Convert.ToSingle(value);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     value.GetType().Name, value,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the Double value '-1.79769313486232E+308' to the Single value -Infinity.
//    Converted the Double value '-13800000000' to the Single value -1.38E+10.
//    Converted the Double value '-1023.299' to the Single value -1023.299.
//    Converted the Double value '-12.98' to the Single value -12.98.
//    Converted the Double value '0' to the Single value 0.
//   Converted the Double value '9.113E-16' to the Single value 9.113E-16.
//    Converted the Double value '103.919' to the Single value 103.919.
//    Converted the Double value '17834.191' to the Single value 17834.19.
//    Converted the Double value '1.79769313486232E+308' to the Single value Infinity.

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Decimal)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen ondalık sayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (decimal value);

Parametreler

value
Decimal

Dönüştürülecek ondalık sayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

value , yuvarlama kullanılarak en yakına yuvarlanır. Örneğin, iki ondalık basameğe yuvarlandığında, 2,345 değeri 2,34 olur ve 2,355 değeri 2,36 olur.

Örnekler

Aşağıdaki örnek, bir değer dizisindeki Decimal her öğeyi bir Single değere dönüştürür.

C#
decimal[] values = { Decimal.MinValue, -1034.23m, -12m, 0m, 147m,
                            199.55m, 9214.16m, Decimal.MaxValue };
float result;

foreach (var value in values)
{
   result = Convert.ToSingle(value);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     value.GetType().Name, value,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the Decimal value '-79228162514264337593543950335' to the Single value -7.9228163E+28.
//    Converted the Decimal value '-1034.23' to the Single value -1034.23.
//    Converted the Decimal value '-12' to the Single value -12.
//    Converted the Decimal value '0' to the Single value 0.
//    Converted the Decimal value '147' to the Single value 147.
//    Converted the Decimal value '199.55' to the Single value 199.55.
//    Converted the Decimal value '9214.16' to the Single value 9214.16.
//    Converted the Decimal value '79228162514264337593543950335' to the Single value 7.9228163E+28.

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(DateTime)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Bu yöntemin çağrılması her zaman oluşturur InvalidCastException.

C#
public static float ToSingle (DateTime value);

Parametreler

value
DateTime

Dönüştürülecek tarih ve saat değeri.

Döndürülenler

Bu dönüşüm desteklenmiyor. Hiçbir değer döndürülmez.

Özel durumlar

Bu dönüşüm desteklenmiyor.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ToSingle(Char)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Bu yöntemin çağrılması her zaman oluşturur InvalidCastException.

C#
public static float ToSingle (char value);

Parametreler

value
Char

Dönüştürülecek Unicode karakteri.

Döndürülenler

Bu dönüşüm desteklenmiyor. Hiçbir değer döndürülmez.

Özel durumlar

Bu dönüşüm desteklenmiyor.

Ayrıca bkz.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

ToSingle(Byte)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen 8 bit işaretsiz tamsayı değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (byte value);

Parametreler

value
Byte

Dönüştürülecek 8 bit işaretsiz tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Örnekler

Aşağıdaki örnek, bayt değerleri dizisindeki her öğeyi bir Single değere dönüştürür.

C#
byte[] numbers = { Byte.MinValue, 10, 100, Byte.MaxValue };
float result;

foreach (byte number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value {1} to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//       Converted the Byte value 0 to the Single value 0.
//       Converted the Byte value 10 to the Single value 10.
//       Converted the Byte value 100 to the Single value 100.
//       Converted the Byte value 255 to the Single value 255.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Boolean)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen Boole değerini eşdeğer tek duyarlıklı kayan nokta sayısına dönüştürür.

C#
public static float ToSingle (bool value);

Parametreler

value
Boolean

Dönüştürülecek Boole değeri.

Döndürülenler

1 sayısı ise valuetrue; değilse, 0.

Örnekler

Aşağıdaki örnek Boole değerlerini ve false değerlerini true değerlere Single dönüştürür.

C#
bool[] flags = { true, false };
float result;

foreach (bool flag in flags)
{
   result = Convert.ToSingle(flag);
   Console.WriteLine("Converted {0} to {1}.", flag, result);
}
// The example displays the following output:
//       Converted True to 1.
//       Converted False to 0.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

ToSingle(Int64)

Kaynak:
Convert.cs
Kaynak:
Convert.cs
Kaynak:
Convert.cs

Belirtilen 64 bit imzalı tamsayının değerini eşdeğer tek duyarlıklı kayan noktalı sayıya dönüştürür.

C#
public static float ToSingle (long value);

Parametreler

value
Int64

Dönüştürülecek 64 bit imzalı tamsayı.

Döndürülenler

ile eşdeğer valueolan tek duyarlıklı kayan noktalı sayı.

Örnekler

Aşağıdaki örnek, uzun tamsayılar dizisindeki her öğeyi bir Single değere dönüştürür.

C#
long[] numbers = { Int64.MinValue, -903, 0, 172, Int64.MaxValue};
float result;

foreach (long number in numbers)
{
   result = Convert.ToSingle(number);
   Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
                     number.GetType().Name, number,
                     result.GetType().Name, result);
}
// The example displays the following output:
//    Converted the Int64 value '-9223372036854775808' to the Single value -9.223372E+18.
//    Converted the Int64 value '-903' to the Single value -903.
//    Converted the Int64 value '0' to the Single value 0.
//    Converted the Int64 value '172' to the Single value 172.
//    Converted the Int64 value '9223372036854775807' to the Single value 9.223372E+18.

Şunlara uygulanır

.NET 9 ve diğer sürümler
Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0