간단한 테스트에서 구조체를 메서드에 전달하면 값으로 전달되지만, 먼저 인터페이스에 할당하면 참조로 전달된다는 것을 알 수 있습니다..NET에서 구조체를 인터페이스 매개 변수가있는 메서드에 전달하면 값에 상자가 생깁니 까?
interface IFoo { int Val { get; set; } }
struct Foo : IFoo { public int Val { get; set; } }
void Bar(IFoo foo) { foo.Val = 1; }
Foo foo = new Foo();
IFoo ifoo = new Foo();
Bar(foo);
Bar(ifoo);
Console.WriteLine(foo.Val); // 0, passed by value
Console.WriteLine(ifoo.Val); // 1, passed by ref
제 질문은, 이렇게 구조체를 전달하기위한 권투 작업이 아직 있습니까?
참조로 전달하는 것은 해당 상황에서 혼란 스럽습니다. 가치에 의해 박스형 가치를 전달합니다. – CodesInChaos