在C#8中,我可以在方法内部创建一个局部函数/方法吗?

在C#8中,我可以在方法内部创建一个局部函数/方法吗?,c#,C#,我有以下代码: public bool ArrangeCardOrder(bool是firsttolast) { 尝试 { if(Settings.Mode.IsLearn()| | | Settings.Mode.isquick()| | |(Settings.Mode.IsPractice()&&Settings.Adp==false)) { 如果(IsFirstToLast) cIndex=cIndex==cIndexLast?0:cIndex++; 其他的 cIndex=cIndex==

我有以下代码:

public bool ArrangeCardOrder(bool是firsttolast)
{
尝试
{
if(Settings.Mode.IsLearn()| | | Settings.Mode.isquick()| | |(Settings.Mode.IsPractice()&&Settings.Adp==false))
{
如果(IsFirstToLast)
cIndex=cIndex==cIndexLast?0:cIndex++;
其他的
cIndex=cIndex==0?cIndexLast:cIndex--;
返回true;
}
while(true)
{
如果(IsFirstToLast)
cIndex=cIndex==cIndexLast?0:cIndex++;
其他的
cIndex=cIndex==0?cIndexLast:cIndex--;
var points=App.viewablePhrases[cIndex]。点;
如果(点==0 | |点==(int)rand.Next(点)+1)
打破
}
}
}
区块:

    if (IsFirstToLast)
        cIndex = cIndex == cIndexLast ? 0 : cIndex++;
    else
        cIndex = cIndex == 0 ? cIndexLast : cIndex--;
重复两次

是否可以在我的方法中为此创建一个本地函数并调用它?

基本上是“是”

public bool ArrangeCardOrder(bool是firsttolast)
{
void DoTheThing()
{
如果(IsFirstToLast)
cIndex=cIndex==cIndexLast?0:cIndex++;
其他的
cIndex=cIndex==0?cIndexLast:cIndex--;
}
尝试
{
如果(/*剪短以简洁*/)
{
DoTheThing();
返回true;
}
while(true)
{
DoTheThing();
// ...

问题:您尝试过吗?如果是,发生了什么?简短回答,“是的,这应该是可能的”C#7支持本地函数,C#8引入了静态本地函数勾选这一点,因为本地函数是C#7中存在的一种功能,“这在C#8中是否可能”的答案是:是。