Why it's not possible to chain ref returns if the inner method also accepts out params in C#7?

后端 未结 1 1703
难免孤独
难免孤独 2021-02-08 10:26

I was experimenting with the new C#7 features and I found something strange. Given the following simplified scenario:

public struct Command
{
}

public class Co         


        
1条回答
  •  攒了一身酷
    2021-02-08 10:57

    you can't call ref return method that has ref or out param

    this change can be fix it

    public ref Command CreateCommandWithIndex(out int index)
            {
                ref Command cmd = ref cb.GetNextCommand(out index);
                return ref cmd;
            }
    

    then when you call this method call it by value

    0 讨论(0)
提交回复
热议问题