本文整理汇总了VB.NET中System.Linq.Enumerable.ElementAtOrDefault<TSource>方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enumerable.ElementAtOrDefault<TSource>方法的具体用法?VB.NET Enumerable.ElementAtOrDefault<TSource>怎么用?VB.NET Enumerable.ElementAtOrDefault<TSource>使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Enumerable.ElementAtOrDefault<TSource>方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: names
' Create an array of strings.
Dim names() As String =
{"Hartono, Tommy", "Adams, Terry", "Andersen, Henriette Thaulow", "Hedlund, Magnus", "Ito, Shu"}
Dim index As Integer = 20
' Get a string at an index that is out of range in the array.
Dim name As String = names.ElementAtOrDefault(index)
Dim text As String = If(String.IsNullOrEmpty(name), "[THERE IS NO NAME AT THIS INDEX]", name)
' Display the output.
Console.WriteLine($"The name chosen at index {index} is {text}")
输出:
The name chosen at index 20 is [THERE IS NO NAME AT THIS INDEX]