如何在C#中的另一个函数内部功能,这可能吗? [英] how to create function inside another function in c#,is it possible?
本文介绍了如何在C#中的另一个函数内部功能,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能建立在C#中的另一个函数内的函数?如果是这样,这可怎么办呢?
Is it possible to create a function inside another function in C#? If so, how can this be done?
推荐答案
这是最可能的。
您可以创建的代表,这是功能内的其他方法。这在C#2.0:
You can create delegates, which are functions, inside other methods. This works in C# 2.0:
public void OuterMethod() {
someControl.SomeEvent += delegate(int p1, string p2) {
// this code is inside an anonymous delegate
}
}
和这部作品在较新版本的lambda表达式:
And this works in newer versions with lambdas:
public void OuterMethod() {
Func<int, string, string> myFunc = (int p1, string p2) => p2.Substring(p1)
}
这篇关于如何在C#中的另一个函数内部功能,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文