当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET FormatException类代码示例

本文整理汇总了VB.NET中System.FormatException的典型用法代码示例。如果您正苦于以下问题:VB.NET FormatException类的具体用法?VB.NET FormatException怎么用?VB.NET FormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FormatException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Main

Module Example
   Public Sub Main()
      Dim price As Decimal = 169.32d
      Console.WriteLine("The cost is {0:Q2}.", price)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:6,代码来源:FormatException

输出:

Unhandled Exception: System.FormatException: Format specifier was invalid.
at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
at System.Decimal.ToString(String format, IFormatProvider provider)
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.IO.TextWriter.WriteLine(String format, Object arg0)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
at Example.Main()

示例2: Main

Module Example
   Public Sub Main()
      Dim price As Decimal = 169.32d
      Console.WriteLine("The cost is {0:C2}.", price)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:6,代码来源:FormatException

输出:

The cost is $169.32.

示例3: Main

Module Example
   Public Sub Main()
      Dim guidString As String = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb"
      Console.WriteLine(Guid.ParseExact(guidString, "G"))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:6,代码来源:FormatException

输出:

Unhandled Exception: System.FormatException: 
Format String can be only "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".
at System.Guid.ParseExact(String input, String format)
at Example.Main()

示例4: Main

Module Example
   Public Sub Main()
      Dim guidString As String = "ba748d5c-ae5f-4cca-84e5-1ac5291c38cb"
      Console.WriteLine(Guid.Parse(guidString))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:6,代码来源:FormatException

输出:

ba748d5c-ae5f-4cca-84e5-1ac5291c38cb

示例5: Main

Module Example
   Public Enum TemperatureScale As Integer
      Celsius
      Fahrenheit
      Kelvin
   End Enum

   Public Sub Main()
      Dim info As String = GetCurrentTemperature()
      Console.WriteLine(info)
   End Sub

   Private Function GetCurrentTemperature() As String
      Dim dat As Date = Date.Now
      Dim temp As Decimal = 20.6d
      Dim scale As TemperatureScale = TemperatureScale.Celsius
      Dim result As String 
      
      result = String.Format("At {0:t} on {1:D}, the temperature is {2:F1} {3:G}",
                             dat, temp, scale)    
      Return result
   End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:23,代码来源:FormatException

输出:

Unhandled Exception: System.FormatException: Format specifier was invalid.
at System.Number.FormatDecimal(Decimal value, String format, NumberFormatInfo info)
at System.Decimal.ToString(String format, IFormatProvider provider)
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at Example.Main()

示例6: Main

Module Example
   Public Enum TemperatureScale As Integer
      Celsius
      Fahrenheit
      Kelvin
   End Enum

   Public Sub Main()
      Dim info As String = GetCurrentTemperature()
      Console.WriteLine(info)
   End Sub

   Private Function GetCurrentTemperature() As String
      Dim dat As Date = Date.Now
      Dim temp As Decimal = 20.6d
      Dim scale As TemperatureScale = TemperatureScale.Celsius
      Dim result As String 
      
      result = String.Format("At {0:t} on {0:D}, the temperature is {1:F1} {2:G}",
                             dat, temp, scale)    
      Return result
   End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:23,代码来源:FormatException

输出:

At 10:40 AM on Wednesday, June 04, 2014, the temperature is 20.6 Celsius

示例7:

Dim n1 As Integer = 10
Dim n2 As Integer = 20
Dim result As String = String.Format("{0 + {1] = {2}", 
                                     n1, n2, n1 + n2)
开发者ID:VB.NET开发者,项目名称:System,代码行数:4,代码来源:FormatException

示例8: Main

' 导入命名空间
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim rnd As New Random()
      Dim numbers(3) As Integer
      Dim total As Integer = 0
      For ctr = 0 To 2
         Dim number As Integer = rnd.Next(1001)
         numbers(ctr) = number
         total += number
      Next
      numbers(3) = total
      Console.WriteLine("{0} + {1} + {2} = {3}", numbers)   
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:FormatException

输出:

Unhandled Exception: 
System.FormatException: 
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.IO.TextWriter.WriteLine(String format, Object arg0)
at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
at Example.Main()

示例9: Main

' 导入命名空间
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim rnd As New Random()
      Dim numbers(3) As Integer
      Dim total As Integer = 0
      For ctr = 0 To 2
         Dim number As Integer = rnd.Next(1001)
         numbers(ctr) = number
         total += number
      Next
      numbers(3) = total
      Dim values(numbers.Length - 1) As Object
      numbers.CopyTo(values, 0) 
      Console.WriteLine("{0} + {1} + {2} = {3}", values)   
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:19,代码来源:FormatException

输出:

477 + 956 + 901 = 2334


注:本文中的System.FormatException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。