C#에서 out
매개 변수에 할당되지 않은 개체 변수를 전달한 다음 할당 할 수없는 이유는 무엇입니까? "는 <xyz>
에 다른 의미를 부여하기 때문 <xyz>
이 범위에서 선언 할 수없는 지역 변수 ..."out 매개 변수에서 할당되지 않은 개체 변수를 전달한 다음 할당 할 수 없습니다.
예 :
내가이 일을하려고하면, 컴파일러 오류가있다.
void MyMethod(int x, out MyObject mo) { **MyObject** mo = new MyObject(); }
// in some other scope:
MyObject mo;
MyMethod(1, out mo);
편집 : 이제 내 실수를 볼 수 있습니다. 위의 코드를 내 코드로 변경했습니다. 별표가있는 MyObject
은 없어야합니다. 당신의 방법 구문이 잘못된 것을 제외하고 out (C# Reference)
The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword.
Although variables passed as an out arguments need not be initialized prior to being passed, the calling method is required to assign a value before the method returns.
문서에서
:-) 결국 있었을 것입니다. 이 오류를 생성하는 정확한 * 코드를 게시하십시오. –
세미콜론 대신 매개 변수 사이에 쉼표를 사용하십시오. 다만 오타라고 예상합니다. –
대신'under' 키워드를 사용해보십시오. –