C#:功能的功能可能吗? [英] C#: Function in Function possible?
本文介绍了C#:功能的功能可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在C#声明中的另一个方法的方法?
例如这样的:
无效OuterMethod()
{
INT任何= 1;
InnedMethod();
无效InnerMethod()
{
INT PlitschPlatsch = 2;
}
}
解决方案
不能直接否定的。 C#不支持内部的方法。它不支持匿名方法虽然可以达到同样的目的。
无效OuterMethod()
{
INT任何= 1;
行动InnedMethod =()=>
{
INT PlitschPlatsch = 2;
};
InnedMethod();
}
Is it possible to declare a method within another method in C#?
For example like that:
void OuterMethod()
{
int anything = 1;
InnedMethod();
void InnerMethod()
{
int PlitschPlatsch = 2;
}
}
解决方案
Not directly no. C# doesn't support inner methods. It does support anonymous methods though which can serve the same purpose
void OuterMethod()
{
int anything = 1;
Action InnedMethod = () =>
{
int PlitschPlatsch = 2;
};
InnedMethod();
}
这篇关于C#:功能的功能可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文