• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET ArgumentOutOfRangeException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Module1

Module Module1
   Public Sub Main()
       Try
           Dim guest1 As Guest = New Guest("Ben", "Miller", 17)
           Console.WriteLine(guest1.GuestInfo)
       Catch outOfRange As ArgumentOutOfRangeException
           Console.WriteLine("Error: {0}", outOfRange.Message)
       End Try
   End Sub
End Module

Class Guest
    Private FirstName As String
    Private LastName As String
    Private Age As Integer

    Public Sub New(ByVal fName As String, ByVal lName As String, ByVal age As Integer)
        MyBase.New()
        FirstName = fName
        LastName = lName
        If (age < 21) Then
            Throw New ArgumentOutOfRangeException("age", "All guests must be 21-years-old or older.")
        Else
            age = age
        End If
    End Sub

    Public Function GuestInfo() As String
        Dim gInfo As String = (FirstName + (" " _
                    + (Me.LastName + (", " + Me.Age.ToString))))
        Return gInfo
    End Function
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:33,代码来源:ArgumentOutOfRangeException


示例2: Example

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

Module Example
   Public Sub Main()
      Dim list As New List(Of String)
      Console.WriteLine("Number of items: {0}", list.Count)
      Try
         Console.WriteLine("The first item: '{0}'", list(0))
      Catch e As ArgumentOutOfRangeException
         Console.WriteLine(e.Message)
      End Try
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:14,代码来源:ArgumentOutOfRangeException

输出:

Number of items: 0
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


示例3: list

If list.Count > 0 Then
   Console.WriteLine("The first item: '{0}'", list(0))
End If
开发者ID:VB.NET开发者,项目名称:System,代码行数:3,代码来源:ArgumentOutOfRangeException


示例4: Main

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

Module Example
   Public Sub Main()
      Dim numbers As New List(Of Integer)
      numbers.AddRange( { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 } )
      
      Dim squares As New List(Of Integer)
      For ctr As Integer = 0 To numbers.Count - 1
         squares(ctr) = CInt(numbers(ctr) ^ 2) 
      Next
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:14,代码来源:ArgumentOutOfRangeException

输出:

Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at Example.Main()


示例5: List

Dim squares As New List(Of Integer)
For ctr As Integer = 0 To numbers.Count - 1
   squares.Add(CInt(numbers(ctr) ^ 2)) 
Next
开发者ID:VB.NET开发者,项目名称:System,代码行数:4,代码来源:ArgumentOutOfRangeException


示例6: Example

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

Module Example
   Public Sub Main()
      Dim list As New List(Of String) 
      list.AddRange( { "A", "B", "C" } )
      ' Get the index of the element whose value is "Z".
      Dim index As Integer = list.FindIndex(AddressOf (New StringSearcher("Z")).FindEquals)
      Try
         Console.WriteLine("Index {0} contains '{1}'", index, list(index)) 
      Catch e As ArgumentOutOfRangeException
         Console.WriteLine(e.Message)
      End Try
   End Sub
End Module

Friend Class StringSearcher
   Dim value As String
   
   Public Sub New(value As String)
      Me.value = value
   End Sub
   
   Public Function FindEquals(s As String) As Boolean
      Return s.Equals(value, StringComparison.InvariantCulture) 
   End Function
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:28,代码来源:ArgumentOutOfRangeException

输出:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


示例7: StringSearcher

' Get the index of the element whose value is "Z".
Dim index As Integer = list.FindIndex(AddressOf (New StringSearcher("Z")).FindEquals)
If index >= 0 Then
   Console.WriteLine("Index {0} contains '{1}'", index, list(index)) 
End If
开发者ID:VB.NET开发者,项目名称:System,代码行数:5,代码来源:ArgumentOutOfRangeException


示例8: Example

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

Module Example
   Public Sub Main()
      Dim list As New List(Of String) 
      list.AddRange( { "A", "B", "C" } )
      Try
         ' Display the elements in the list by index.
         For ctr As Integer = 0 To list.Count
            Console.WriteLine("Index {0}: {1}", ctr, list(ctr)) 
         Next   
      Catch e As ArgumentOutOfRangeException
         Console.WriteLine(e.Message)
      End Try
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:ArgumentOutOfRangeException

输出:

Index 0: A
Index 1: B
Index 2: C
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


示例9: list

' Display the elements in the list by index.
For ctr As Integer = 0 To list.Count - 1 
   Console.WriteLine("Index {0}: {1}", ctr, list(ctr)) 
Next
开发者ID:VB.NET开发者,项目名称:System,代码行数:4,代码来源:ArgumentOutOfRangeException


示例10: Main

Module Example
   Public Sub Main()
       Dim words() As String = { "the", "today", "tomorrow", " ", "" }
       For Each word In words
          Console.WriteLine("First character of '{0}': '{1}'", 
                            word, GetFirstCharacter(word))
       Next                     
   End Sub
   
   Private Function GetFirstCharacter(s As String) As Char
      Return s(0)
   End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:13,代码来源:ArgumentOutOfRangeException

输出:

First character of 'the': 't'
First character of 'today': 't'
First character of 'tomorrow': 't'
First character of ' ': ' '

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Example.Main()


示例11: GetFirstCharacter

Function GetFirstCharacter(s As String) As Char
   If String.IsNullOrEmpty(s) Then 
      Return ChrW(0)
   Else   
      Return s(0)
   End If   
End Function
开发者ID:VB.NET开发者,项目名称:System,代码行数:7,代码来源:ArgumentOutOfRangeException


示例12: Main

Module Example
   Public Sub Main()
      Dim phrases() As String = { "ocean blue", "concerned citizen", 
                                  "runOnPhrase" }
      For Each phrase In phrases
         Console.WriteLine("Second word is {0}", GetSecondWord(phrase))
      Next                            
  End Sub
  
  Function GetSecondWord(s As String) As String
     Dim pos As Integer = s.IndexOf(" ")
     Return s.Substring(pos).Trim()
  End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:14,代码来源:ArgumentOutOfRangeException

输出:

Second word is blue
Second word is citizen

Unhandled Exception: System.ArgumentOutOfRangeException: StartIndex cannot be less than zero.
Parameter name: startIndex
at System.String.Substring(Int32 startIndex, Int32 length)
at Example.GetSecondWord(String s)
at Example.Main()


示例13: Main

Module Example
   Public Sub Main()
      Dim phrases() As String = { "ocean blue", "concerned citizen", 
                                  "runOnPhrase" }
      For Each phrase In phrases
         Dim word As String = GetSecondWord(phrase)
         If Not String.IsNullOrEmpty(word) Then _
            Console.WriteLine("Second word is {0}", word)
      Next                            
   End Sub
  
   Function GetSecondWord(s As String) As String
      Dim pos As Integer = s.IndexOf(" ")
      If pos >= 0
          Return s.Substring(pos).Trim()
      Else
         Return String.Empty
      End If
  End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:20,代码来源:ArgumentOutOfRangeException

输出:

Second word is blue
Second word is citizen


示例14: Main

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

Module Example
   Public Sub Main()
      Dim sentence As String = "This is a simple, short sentence."
      Console.WriteLine("Words in '{0}':", sentence)
      For Each word In FindWords(sentence)
         Console.WriteLine("   '{0}'", word)
      Next
   End Sub
   
   Function FindWords(s As String) As String()
      Dim start, ending As Integer
      Dim delimiters() As Char = { " "c, "."c, ","c, ";"c, ":"c,
                                   "("c, ")"c }
      Dim words As New List(Of String)()

      Do While ending >= 0
         ending = s.IndexOfAny(delimiters, start)
         If ending >= 0
            If ending - start > 0 Then
               words.Add(s.Substring(start, ending - start)) 
            End If
            start = ending + 1
         Else
            If start < s.Length - 1 Then
               words.Add(s.Substring(start))
            End If      
         End If
      Loop    
      Return words.ToArray()                         
   End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:34,代码来源:ArgumentOutOfRangeException

输出:

Words in 'This is a simple, short sentence.':
This'
is'
a'
simple'
short'
sentence'


示例15: Example

Module Example
   Public Sub Main()
      Dim dimension1 As Integer = 10
      Dim dimension2 As Integer = -1
      Try
         Dim arr AS Array = Array.CreateInstance(GetType(String), 
                                                 dimension1, dimension2)
      Catch e As ArgumentOutOfRangeException
         If e.ActualValue IsNot Nothing Then
            Console.WriteLine("{0} is an invalid value for {1}: ", 
                              e.ActualValue, e.ParamName)
         End If                     
         Console.WriteLine(e.Message)
      End Try
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:ArgumentOutOfRangeException

输出:

Non-negative number required.
Parameter name: length2


示例16:

Dim dimension1 As Integer = 10
Dim dimension2 As Integer = 10
Dim arr As Array = Array.CreateInstance(GetType(String), 
                                        dimension1, dimension2)
开发者ID:VB.NET开发者,项目名称:System,代码行数:4,代码来源:ArgumentOutOfRangeException


示例17:

If dimension1 < 0 OrElse dimension2 < 0 Then
   Console.WriteLine("Unable to create the array.")
   Console.WriteLine("Specify non-negative values for the two dimensions.")
Else
   arr = Array.CreateInstance(GetType(String), 
                              dimension1, dimension2)   
End If
开发者ID:VB.NET开发者,项目名称:System,代码行数:7,代码来源:ArgumentOutOfRangeException


示例18: Main

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

Public Class Continent
   Public Property Name As String
   Public Property Population As Integer
   Public Property Area As Decimal  
End Class

Module Example
   Dim continents As New List(Of Continent)
   Dim msg As String 
      
   Public Sub Main()
      Dim names() As String = { "Africa", "Antarctica", "Asia", 
                                     "Australia", "Europe", "North America",
                                     "South America" }
      ' Populate the list.
      For Each name In names
         Dim th As New Thread(AddressOf PopulateContinents)
         th.Start(name)
      Next              
      Console.WriteLine(msg)
      Console.WriteLine()

      ' Display the list.
      For ctr As Integer = 0 To names.Length - 1
         Dim continent = continents(ctr)
         Console.WriteLine("{0}: Area: {1}, Population {2}", 
                           continent.Name, continent.Population,
                           continent.Area)
      Next
   End Sub
   
   Private Sub PopulateContinents(obj As Object)
      Dim name As String = obj.ToString()
      msg += String.Format("Adding '{0}' to the list.{1}", name, vbCrLf)
      Dim continent As New Continent()
      continent.Name = name
      ' Sleep to simulate retrieving remaining data.
      Thread.Sleep(50)
      continents.Add(continent)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:45,代码来源:ArgumentOutOfRangeException

输出:

Adding 'Africa' to the list.
Adding 'Antarctica' to the list.
Adding 'Asia' to the list.
Adding 'Australia' to the list.
Adding 'Europe' to the list.
Adding 'North America' to the list.
Adding 'South America' to the list.



Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at Example.Main()


示例19: Main

' 导入命名空间
Imports System.Collections.Concurrent
Imports System.Threading

Public Class Continent
   Public Property Name As String
   Public Property Population As Integer
   Public Property Area As Decimal  
End Class

Module Example
   Dim continents As New ConcurrentBag(Of Continent)
   Dim gate As CountdownEvent
   Dim msg As String = String.Empty
      
   Public Sub Main()
      Dim names() As String = { "Africa", "Antarctica", "Asia", 
                                "Australia", "Europe", "North America",
                                "South America" }
      gate = new CountdownEvent(names.Length)
      
      ' Populate the list.
      For Each name In names
         Dim th As New Thread(AddressOf PopulateContinents)
         th.Start(name)
      Next              

      ' Display the list.
      gate.Wait()
      Console.WriteLine(msg)
      Console.WriteLine()

      For ctr As Integer = 0 To names.Length - 1
         Dim continent = continents(ctr)
         Console.WriteLine("{0}: Area: {1}, Population {2}", 
                           continent.Name, continent.Population,
                           continent.Area)
      Next
   End Sub
   
   Private Sub PopulateContinents(obj As Object)
      Dim name As String = obj.ToString()
      SyncLock msg 
         msg += String.Format("Adding '{0}' to the list.{1}", name, vbCrLf)
      End SyncLock
      Dim continent As New Continent()
      continent.Name = name
      ' Sleep to simulate retrieving remaining data.
      Thread.Sleep(25)
      continents.Add(continent)
      gate.Signal()
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:53,代码来源:ArgumentOutOfRangeException

输出:

Adding 'Africa' to the list.
Adding 'Antarctica' to the list.
Adding 'Asia' to the list.
Adding 'Australia' to the list.
Adding 'Europe' to the list.
Adding 'North America' to the list.
Adding 'South America' to the list.


Africa: Area: 0, Population 0
Antarctica: Area: 0, Population 0
Asia: Area: 0, Population 0
Australia: Area: 0, Population 0
Europe: Area: 0, Population 0
North America: Area: 0, Population 0
South America: Area: 0, Population 0



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET CodeAssignStatement类代码示例发布时间:2022-05-24
下一篇:
VB.NET NativeActivity<TResult>类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap