作者sakyer (石理克)
看板C_Sharp
标题[问题] 如何在C#实现JS的 callBack ?
时间Wed Jun 14 10:59:14 2017
问题网页版:
https://goo.gl/uPmWK4
问题图片版:
https://goo.gl/lmLtoh
为了从别人的程式码学习 c# ,我正试着将一个JS程式重写成C#。
其中这段 eachCell 方法不知道在 C# 中该如何实现...
烦请各位大大给予建议与指教,谢谢!
// Get available cells in Grid =========================
Grid.prototype.availableCells = function () {
var cells = [];
this.eachCell(function (x, y, tile) {
if (!tile) {
cells.push({ x: x, y: y });
}
});
return cells;
};
// Call callback for every cell=========================
Grid.prototype.eachCell = function (callback) {
for (var x = 0; x < this.size; x++) {
for (var y = 0; y < this.size; y++) {
callback(x, y, this.cells[x][y]);
}
}
};
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.251.182.68
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1497409158.A.C46.html
1F:推 vi000246: 就是你底下写的这个啊Grid.prototype.eachCell 06/14 11:46
2F:→ vi000246: 看懂你的问题了 你可以google 委派 06/14 11:47
3F:→ sakyer: 恩 其实不太会用委派解我这状况 06/14 13:02
5F:→ vi000246: 不宣告delegate的话可以用Func 06/14 14:26
7F:→ sakyer: 喔喔!来试试看 06/14 15:25
8F:推 t64141: 关键字 func<> , action<>, linq 06/14 23:33
9F:→ sakyer: 知道怎样用lambda解了!感谢大家提供指教 06/15 13:11