使用下面的C#代码,您将如何在Visual Basic中编写它?它试图说什么?
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Microsoft.LiveLabs.Pivot
{
/// <summary>
/// Tile Builder class
/// </summary>
public static class TileBuilder
{
/// <summary>
/// Specifies which images are required in the images array used in CreateTile
/// according to the Morton fractal pattern used by Seadragon.
/// </summary>
/// <remarks>
/// Usage of this and CreateTile are kind of tricky. Here's an example:
/// Say you have a results …Run Code Online (Sandbox Code Playgroud) 我不是一个python的家伙,我想了解一些python代码.我想知道下面代码的最后几行是做什么的?这种多个对象是否被返回?还是返回了3个对象的列表?
req = SomeRequestBean()
req.setXXX(xxx)
req.YYY = int(yyy)
device,resp,fault = yield req #<----- What does this mean ?
Run Code Online (Sandbox Code Playgroud) 好吧,当我在构建一个自定义枚举器时,我注意到了这种与收益率有关的行为
说你有这样的事情:
public class EnumeratorExample
{
public static IEnumerable<int> GetSource(int startPoint)
{
int[] values = new int[]{1,2,3,4,5,6,7};
Contract.Invariant(startPoint < values.Length);
bool keepSearching = true;
int index = startPoint;
while(keepSearching)
{
yield return values[index];
//The mind reels here
index ++
keepSearching = index < values.Length;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在技术上从函数返回之后,是什么让编译器的底层可以执行索引++和while循环中的其余代码?
我目前正在为夏季项目学习MyHDL.我有一个问题,掌握屈服声明的功能.尽管MyHDL基于python是正确的,但它以专门的方式使用其yield语句.相同的链接是:http: //www.myhdl.org/doc/current/manual/reference.html#myhdl.always
它指出: MyHDL生成器是具有专门yield语句的标准Python生成器.在硬件描述语言中,等效语句称为敏感性列表.MyHDL生成器中yield语句的一般格式是:yield clause [,clause ...]当生成器执行yield语句时,它的执行在该点暂停.同时,每个子句都是一个触发器对象,它定义了应该恢复生成器的条件.但是,每次调用yield语句时,无论子句数是多少,生成器都会恢复一次.这发生在发生的第一个触发器上.
我无法理解它.有人可以用简单的语言解释一下吗?或者可能将我重定向到另一个来源?
如果你能提供帮助,我将不胜感激.谢谢!
问候
在我的django活塞API中,我想在调用另一个需要一段时间的函数之前向客户端发出/返回一个http响应.如何使yield产生包含所需JSON的HTTP响应,而不是与生成器对象的创建相关的字符串?
我的活塞处理程序方法如下所示:
def create(self, request):
data = request.data
*other operations......................*
incident.save()
response = rc.CREATED
response.content = {"id":str(incident.id)}
yield response
manage_incident(incident)
Run Code Online (Sandbox Code Playgroud)
而不是我想要的响应,如:
{"id":"13"}
Run Code Online (Sandbox Code Playgroud)
客户端获取如下字符串:
"<generator object create at 0x102c50050>"
Run Code Online (Sandbox Code Playgroud)
编辑:
我意识到使用yield是错误的方法,实质上我想要实现的是客户端在服务器进入manage_incident()的时间代价高昂的函数之前立即收到响应
我正在尝试使用yield和创建动态内容content_for.基本上我有一堆布局.我不想为每个布局创建一堆视图.我想在需要时渲染视图部件.对于代码的不同部分,它是可以的.但我有相同的部分与不同的内容有问题.
在我的 application.html.erb
<%= yield %>
<%= yield :name_section %>
Run Code Online (Sandbox Code Playgroud)
在我的show.html.erb拥有;
<% content_for :name_section do %>
<b>Name:</b>
<%= @post.name %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这是个问题;
如果我想要多个具有不同内容的name_section,该怎么办?我的意思是; 我想:name_section在不同的内容中放置不同的地方.
对于前
<table>
<tr>
<td>
<%= yield :name_section %>
</td>
</tr>
<tr>
<td>
<%= yield :name_section %>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢.Çağdaş
我刚安装Laravel 4(照亮)和我在浏览器中打开index.php文件,我遇到了这个错误:
解析错误:语法错误,意外的'yield'(T_YIELD),期望标识符(T_STRING)在第339行/www/Laravel4/vendor/illuminate/view/src/Illuminate/View/Environment.php
我已经修复了元文件夹的权限,并通过Composer安装了所有依赖项.我在OSX 10.8.2上运行PHP版本5.5.0alpha2.
以下代码的工作正确:
def file_gen(f_name):
f = open(f_name)
for line in f:
yield line
gen_line = file_gen("foo.html")
gen_line.next() # '<!DOCTYPE>\n'
gen_line.next() # '<html> \n'
gen_line.next() # ... next line in file
Run Code Online (Sandbox Code Playgroud)
但是这个功能提升了StopIteration.我不明白为什么?
def file_gen(f_name):
f = open(f_name)
line = f.readline()
yield line
gen_line = file_gen('foo.html')
gen_line.next() # '<!DOCTYPE>\n'
gen_line.next() # StopIteration
Run Code Online (Sandbox Code Playgroud) 我一直在Ruby中编写相同的代码模式,看起来它会受益于'do'样式的代码,但我不确定如何编写该方法.
我一直在做这种代码模式,它以相同的代码行开始和结束......
x.increment!(:step_count) # same each time
# ...then some different code each
x.update_column(:step_description, "blerg message") # same each time
Run Code Online (Sandbox Code Playgroud)
我觉得它会受益于'做'这样的东西......
update_steps "blerg message" do
# ...then some different code each
end
Run Code Online (Sandbox Code Playgroud)
然后在'do'内部每次执行公共代码.
我将如何制作一个可以使用'do'的方法.
谢谢!
编辑:我认为不要关闭它是很重要的,因为我不知道要搜索'block'或'yield'.可能不知道这些术语的人最终可能会搜索"do".
我在MDN上偶然发现了生成器函数,让我感到困惑的是以下示例:
function* logGenerator() {
console.log(yield);
console.log(yield);
console.log(yield);
}
var gen = logGenerator();
// the first call of next executes from the start of the function
// until the first yield statement
gen.next();
gen.next('pretzel'); // pretzel
gen.next('california'); // california
gen.next('mayonnaise'); // mayonnaise
Run Code Online (Sandbox Code Playgroud)
我不明白的是为什么作为yield参数的语句console.log返回传递给.next()生成器方法的参数.这是否发生是因为空yield必须返回.next()方法的第一个参数的值?
我还尝试了一些例子,似乎证实了上述陈述:
gen.next(1,2,3); // the printed value is 1, the 2 and 3 are ignored
// and the actual yielded value is undefined
Run Code Online (Sandbox Code Playgroud)
还有一种方法可以访问.next() …
yield ×10
python ×3
c# ×2
generator ×2
content-for ×1
django ×1
enumeration ×1
erb ×1
javascript ×1
laravel ×1
loops ×1
myhdl ×1
php ×1
ruby ×1
syntax ×1
vb.net ×1
yield-return ×1