我想知道in
关键字与ReadOnlyMemory<T>
和ReadOnlySpan<T>
的用法是什么。
void Method(ReadOnlyMemory<int> memory)
{
// Code that modifies memory wont reflect out of this scope.
memory = memory.Slice(3);
}
void Method(in Memory<int> memory)
{
// same thing as the above
memory.Slice(3);
}
void Method(in ReadOnlyMemory<int> memory)
{
// is there any performance gain here or something?
}
基本上使用in
或ReadOnly
(Span
/ Memory
)是否与const typename &
(C ++)类似?