VB で 関数プログラミングっぽいことをするのに便利なように Head や Tail をくっつけてみました。
Imports System Imports System.Collections.Generic Public Class ListObject Private Lstr As New List(Of Object) Sub New() Me.Lstr = New List(Of Object) Lstr.Add(Nothing) End Sub Public Function Head() Return Lstr(0) End Function Public Function Last() Return Lstr(Lstr.Count - 2) End Function Public Function Last2() Return Lstr(Lstr.Count) End Function Public Sub Clear() Lstr.Clear() Lstr.Add(Nothing) End Sub Public Function Tail() Dim Tarray() As Object = New Object(Lstr.Count) {} Dim i As Object Dim TailList As New ListObject Lstr.CopyTo(1, Tarray, 0, Lstr.Count - 1) TailList.Clear() For Each i In Tarray TailList.Add(i) Next i Return TailList End Function Public Sub Add(ByRef value As Object) Lstr(Lstr.Count - 1) = value Lstr.Add(Nothing) End Sub Public Function Show() Return "[" + AllList(Me) + "]" End Function Private Function AllList(ByRef list As ListObject) If IsNothing(list.Head) Then Return "" Else Return Tostr(list.Head()) + sPace(list.Tail) + AllList(list.Tail) End If End Function Private Function IsNothing(ByRef cell As Object) If TypeOf cell Is ListObject Then Return False Else If cell = Nothing Then Return True Else Return False End If End If End Function Private Function Tostr(ByRef cell As Object) If TypeOf cell Is ListObject Then Return cell.Show Else If TypeOf cell Is String Then Return """" + cell + """" Else Return cell.ToString End If End If End Function Private Function sPace(ByRef list As ListObject) If IsNothing(list.Head) Then Return "" Else Return " " End If End Function End Class Module Module1 Sub Main() Dim Lstr As New ListObject Dim Lstr2 As New ListObject Dim Lnum As New ListObject Dim LList As New ListObject Lstr.Add("0:あいうえお") Lstr.Add("1:かきくけこ") Lstr.Add("2:さしすせそ") Lstr.Add("3:たちつてと") Lstr2.Add("a:abcde") Lstr2.Add("b:12345") Lstr2.Add("c:fghij") Lstr2.Add("d:hogeh") Lnum.Add(123) Lnum.Add(456) Lnum.Add(7890) System.Console.WriteLine("Lstr.Show =" + Lstr.Show) 'Lstr.Show =["0:あいうえお" "1:かきくけこ" "2:さしすせそ" "3:たちつてと"] System.Console.WriteLine("Lstr2.Show =" + Lstr2.Show) 'Lstr2.Show =["a:abcde" "b:12345" "c:fghij" "d:hogeh"] System.Console.WriteLine("Lnum.Show =" + Lnum.Show) 'Lnum.Show =[123 456 7890] System.Console.WriteLine("Lstr.Head =" + Lstr.Head) 'Lstr.Head = 0 : あいうえお System.Console.WriteLine("Lstr.Tail.Show =" + Lstr.Tail.Show) 'Lstr.Tail.Show =["1:かきくけこ" "2:さしすせそ" "3:たちつてと"] System.Console.WriteLine("Lstr.Last =" + Lstr.Last) 'Lstr.Last = 3 : たちつてと() LList.Add(Lstr) LList.Add(Lstr2) LList.Add(Lnum) System.Console.WriteLine("LList.Show =" + LList.Show) 'LList.Show =[["0:あいうえお" "1:かきくけこ" "2:さしすせそ" "3:たちつてと"] ["a:abcde" "b:12345" "c:fghij" "d:hogeh"] ' [123 456 7890]] System.Console.WriteLine("LList.Head.Head=" + LList.Head.Head) 'LList.Head.Head = 0 : あいうえお End Sub End Module
機能としては、cons の代りに Add(・・・) でリストを作って、Head でリストの先頭を取得して、残りを Tail で取得。Show でリストを表示。