[英]Execute code as string vb.net
Is this possible to do?这是可能的吗?
Public Function MyFunc() as Integer
dim I as integer
Execute("I = 50")
Return I
End Function
I mean can I execute code like that in a function?我的意思是我可以在函数中执行这样的代码吗?
Edit1: I asked another question here: Checkpoints in functions VB.NET编辑 1:我在这里问了另一个问题: 函数 VB.NET 中的检查点
I have a Queue in there name of labels , when I dequeue I want to run something like this:我有一个名为 labels 的 Queue ,当我出队时,我想运行这样的事情:
Dim Queue as new Queue(of string)
Queue.Enqueue("Checkpoint1")
Queue.Enqueue("Checkpoint2")
Dim i =Queue.dequeue()
GoTo I
But I can't set this labels dynamically and I wanted to know is there any way to achieve sth like this or not?但是我不能动态设置这个标签,我想知道有没有办法实现这样的目标?
Based on your linked question, here's the kind of thing that you need:根据您链接的问题,这是您需要的类型:
Dim choices = New Dictionary(Of String, Action) From
{
{ "Apple", Sub () Console.WriteLine("I Love Apples") },
{ "Banana", Sub () Console.WriteLine("I Go Ape Over Bananas") }
}
choices("Banana").Invoke()
This outputs "I Go Ape Over Bananas"
to the Console.这会将
"I Go Ape Over Bananas"
输出到控制台。
See https://stackoverflow.com/a/46440962/259769 for a more specific implementation that you need.有关您需要的更具体的实现,请参阅https://stackoverflow.com/a/46440962/259769 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.