В следующем упрощенном сценарии:
Код: Выделить всё
public struct Command
{
}
public class CommandBuffer
{
private Command[] commands = new Command[1024];
private int count;
public ref Command GetNextCommand()
{
return ref commands[count++];
}
public ref Command GetNextCommand(out int index)
{
index = count++;
return ref commands[index];
}
}
public class BufferWrapper
{
private CommandBuffer cb = new CommandBuffer();
// this compiles fine
public ref Command CreateCommand()
{
ref Command cmd = ref cb.GetNextCommand();
return ref cmd;
}
// doesn't compile
public ref Command CreateCommandWithIndex()
{
ref Command cmd = ref cb.GetNextCommand(out int index);
return ref cmd;
}
}
Код: Выделить всё
CS8157 Cannot return 'cmd' by reference because it was initialized to a value that cannot be returned by reference
Подробнее здесь: https://stackoverflow.com/questions/459 ... ccepts-out
Мобильная версия