Just a quick blog post demonstrate a way generating the Fibonacci Sequence with LINQ.
Public Module FibExample
Public Const ɸ As Decimal = 1.6180339887498949D
'
Public Function Fib(n As Integer) As IEnumerable(Of Decimal)
Dim v As Decimal = 1D
Return Enumerable.Range(0, n).Select(Function(i) If(i < 2, i,If(i = 2, 1, v.SetValue(Math.Round(v * ɸ)))))
End Function
<System.Runtime.CompilerServices.Extension()>
Public Function SetValue(Of T)(ByRef dest As T, value As T) As T
dest = value
Return value
End Function
End Module
2 Comments On This Entry
Page 1 of 1
Jstall
05 August 2012 - 07:37 PM
Neat example.
Ahhh LINQ, such a powerful concept I've been trying to incorporate into the work I've been doing since starting at a .NET shop six months ago. I try to use it where it makes sense although I admit I often struggle with the syntax, jumping from C# to VB all the time doesn't help either
Ahhh LINQ, such a powerful concept I've been trying to incorporate into the work I've been doing since starting at a .NET shop six months ago. I try to use it where it makes sense although I admit I often struggle with the syntax, jumping from C# to VB all the time doesn't help either
Page 1 of 1
|
|



2 Comments








|