Код: Выделить всё
void Foo(ref int m /* caller-context */) {
int n = 0; // declaration-block
ref int p = ref m; // caller-context
p = ref n; /* CS8374:
* Cannot ref-assign source
* has a narrower escape scope
* than destination.
*/
}
Код: Выделить всё
void Bar(int m /* function-member */) {
int n = 0; // declaration-block
ref int p = ref m; // function-member
p = ref n; // function-member = ref declaration-block
}
< /code>
Я ожидал, что он вызвал CS8374, как foo < /code> do, но компиляция успешная. Его ref-safe-context такой же, как и фек-safe-context в его инициализируемом выражении. Функциональный член Код: Выделить всё
public class C
{
public void M4(int p)
{
// context of r2 is declaration-block,
// ref safe context of p is function-member
ref int r2 = ref p;
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... o-local-va
Мобильная версия