delphi 中 C# 的等价收益 return
Equivalent of yield return of C# in delphi
我正在将 C# 代码转换为 Delphi 2010.I 我一直在寻找等价于 delphi 中 C# 的产量 return。
有人可以帮忙吗?
根本没有等价物。 Delphi 没有任何匹配功能。在 C# 中,yield return
用于 C# 迭代器方法,而 Delphi 与 C# 迭代器方法完全不同。
在Delphi中你需要手动编写迭代器,没有迭代器方法的语法糖。 documentation.
中对此进行了描述
在 delphi 中至少有两个 Yield 实现(虽然都不理想)。
首先是使用 asm 魔法,这里:http://santonov.blogspot.ru/2007/10/yield-you.html
其次是使用 Win32 纤程(非常轻量级的线程),因此仅适用于 windows。在这里:http://www.gerixsoft.com/blog/delphi/yield
还有一个基于纤程的实现,可读性稍差:http://delphisorcery.blogspot.ru/2011/04/yield-return-and-delphi.html
也就是说,如果您是 Delphi 的新手,我不建议您使用 yield,因为它在 Delphi 中不是常见的编程方式。所以只有当你了解后果时才使用它。
Delphi https://github.com/Purik/AIO
有基于协程的框架
您可以在此处查看生成器示例(如 Python)- https://github.com/Purik/AIO/blob/master/Demos/Tutorial/Generator.dpr
我正在将 C# 代码转换为 Delphi 2010.I 我一直在寻找等价于 delphi 中 C# 的产量 return。 有人可以帮忙吗?
根本没有等价物。 Delphi 没有任何匹配功能。在 C# 中,yield return
用于 C# 迭代器方法,而 Delphi 与 C# 迭代器方法完全不同。
在Delphi中你需要手动编写迭代器,没有迭代器方法的语法糖。 documentation.
中对此进行了描述在 delphi 中至少有两个 Yield 实现(虽然都不理想)。
首先是使用 asm 魔法,这里:http://santonov.blogspot.ru/2007/10/yield-you.html
其次是使用 Win32 纤程(非常轻量级的线程),因此仅适用于 windows。在这里:http://www.gerixsoft.com/blog/delphi/yield
还有一个基于纤程的实现,可读性稍差:http://delphisorcery.blogspot.ru/2011/04/yield-return-and-delphi.html
也就是说,如果您是 Delphi 的新手,我不建议您使用 yield,因为它在 Delphi 中不是常见的编程方式。所以只有当你了解后果时才使用它。
Delphi https://github.com/Purik/AIO
有基于协程的框架您可以在此处查看生成器示例(如 Python)- https://github.com/Purik/AIO/blob/master/Demos/Tutorial/Generator.dpr