由网友(佛说要宠我)分享简介:是否有可能在C#声明中的另一个方法的方法?例如这样的:无效OuterMethod(){INT任何= 1;InnedMethod();无效InnerMethod(){INT PlitschPlatsch = 2;}}解决方案 不能直接否定的。 C#不支持内部的方法。它不支持匿名方法虽然可以达到同样的目的。无效Oute...
是否有可能在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();
}
相关推荐
最新文章