Предотвращает ли передача интерфейса с использованием модификатора параметра «in» копирование значений, если этот интерф ⇐ C#
Предотвращает ли передача интерфейса с использованием модификатора параметра «in» копирование значений, если этот интерф
I have an interface that is implemented on several readonly structs that are passed around in a tight loop using the in parameter modifier. My understanding of the in keyword is that it can be used when passing readonly structs to prevent values from being copied, thus improving performance, especially if the structs are not small.
public interface ISomeInterface { } public readonly struct SomeStruct : ISomeInterface { } public void DoSomething(in SomeStruct someStruct) { } This interface will only be implemented on readonly structs. I want to know if the in keyword will prevent value copies if the method parameter is of type ISomeInterface:
SomeStruct someStruct = new SomeStruct(...); DoSomethingElse(in someStruct); public void DoSomethingElse(in ISomeInterface someInterface) { } I am not sure about this because someStruct is a readonly struct, but the method defines it as ISomeInterface.
Источник: https://stackoverflow.com/questions/781 ... lue-copies
I have an interface that is implemented on several readonly structs that are passed around in a tight loop using the in parameter modifier. My understanding of the in keyword is that it can be used when passing readonly structs to prevent values from being copied, thus improving performance, especially if the structs are not small.
public interface ISomeInterface { } public readonly struct SomeStruct : ISomeInterface { } public void DoSomething(in SomeStruct someStruct) { } This interface will only be implemented on readonly structs. I want to know if the in keyword will prevent value copies if the method parameter is of type ISomeInterface:
SomeStruct someStruct = new SomeStruct(...); DoSomethingElse(in someStruct); public void DoSomethingElse(in ISomeInterface someInterface) { } I am not sure about this because someStruct is a readonly struct, but the method defines it as ISomeInterface.
Источник: https://stackoverflow.com/questions/781 ... lue-copies
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение