我正在尝试做一些在python中可以做到的事情:
class Spam():
def print_four_numbers(a, b, c, d):
print a, b, c, d
class Beacon():
def bar(SpamInstance):
return SpamInstance.print_four_numbers
B, S = Beacon(), Spam()
这里的关键是上面的代码允许我这样做:
>>>B.bar(S)(1, 2, 3, 4)
1 2 3 4
如何使用C#执行类似的操作?如果它改变了什么,我需要“print\u four\u numbers”方法重载3-4次。我读过关于代表和事件的文章,但是他们在这里工作吗(以及如何工作)?你知道吗
我也知道,这可以通过简单地将所有这些参数传递给bar()
并将它们“传递”给另一个函数来解决,但是我不喜欢有很多参数的方法。你知道吗
谢谢!你知道吗
PrintFourNumbers
方法非常难看;如果它接受整数数组,看起来会更好,但是我想让它尽可能接近问题中的示例。你知道吗相关问题 更多 >
编程相关推荐