这是我遇到的问题的代码。这很简单,但我仍在学习。我想缓存结果,以便函数比现在快几秒钟返回。目前它在 4 中返回给调用者,而它应该是 2。
Sub Main
console.writeline(getmyresult(2)) 'takes a while'
console.writeline(getmyresult(3)) 'takes a while'
console.writeline(getmyresult(2)) 'Should be instant'
console.writeline(getMyresult(3)) 'Should be instant'
End Sub
function getMyresult(X as interger) as integer
dim Y as integer=LongCompute(X)
return Y
end function
function LongCompute(X as integer) as integer
system.threading.thread.sleep(1000)
return x^2
end function
任何帮助将不胜感激。