2013-06-05 3 views
0
namespace Electronic_Filing_of_Appeals 
{ 
public class GenerateXML 
{ 
    public ElectronicRecordAppellateCase CreateXml() 
    { 

이 코드의 CreateXML() 부분에 있습니다. 모든 코드 경로가 접근 값"모든 코드 경로가 값을 반환하지는 않습니다."

내가 다른 시도했지만 같은 결과를 반환 :이 오류는 다시 걷어

Electronic_Filing_of_Appeals.GenerateXML.CreateXml을()입니다된다.

실마리가 있습니까?

+6

이 방법 자체가 아니라 정의 ... – walther

+2

확인 값을 반환하지 그것은 PO하지 않으면 당신이 게시 한 것을 통해 말할 수 있습니다. 오류는 아무 것도 반환하지 않는 코드 경로가 있음을 의미합니다 ('else', 'case'등이 누락되었습니다). – Oded

+0

제목을 편집했습니다. "[제목에"태그 "가 포함되어 있어야합니까?] (http://meta.stackexchange.com/questions/19190/)"합의가 "아니오, 그렇지 않아야합니다"로 표시되어야합니다. –

답변

2

귀하의 방법은 ElectronicRecordAppellateCase 클래스의 인스턴스를 반환하는 데 동의합니다. 결과가 인 경우 결과가 인 경우 결과가 좋을 것 같습니다.

public ElectronicRecordAppellateCase CreateXml() 
{ 
    ElectronicRecordAppellateCase output=new ElectronicRecordAppellateCase(); 
    if(someVariableAlreadyDefined>otherVariable) 
    { 
    //do something useful 
    return output; 
    } 

// Not returning anything if the if condition is not true!!!! 

} 

솔루션 : 당신이 방법에서 유효한 반환 값을 반환하고 있는지 확인하십시오.

public ElectronicRecordAppellateCase CreateXml() 
{ 
    ElectronicRecordAppellateCase output=new ElectronicRecordAppellateCase(); 
    if(someVariableAlreadyDefined>otherVariable) 
    { 
    return output; 
    } 
    return null; //you can return the object here as needed 
} 
+0

빠른 답변을 보내 주셔서 감사합니다. 나는 나의 코드의 끝에서 나의 "return"을 잊었다는 것을 깨달았다. 너 모두 락! –

+0

@RaymondBeyrle 안녕하세요. 다행이 도울 수있어 :) – Shyju

2

출력 유형을 지정하면 코드의 모든 경로 다음에 값을 제공해야합니다. 이 오류가 표시되면 메서드에서 하나 이상의 시나리오가 지정된 형식의 값을 반환하지 않지만 메서드가 종료됩니다.

public ElectronicRecordAppellateCase CreateXml() 
{ 
    if (something) 
    { 
     return new ElectronicRecordAppellateCase(); 
    } 
    // if the something is false, the method doesn't provide any output value!!! 
} 

이것은 예를 들어 다음과 같이 해결할 수 :

public ElectronicRecordAppellateCase CreateXml() 
{ 
    if (something) 
    { 
     return new ElectronicRecordAppellateCase(); 
    } 
    else return null; // "else" isn't really needed here 
} 

패턴을 참조하십시오

이 같은 문제 방법의 예입니다?

1

가 모든 코드 경로가 당신이 그렇게 내가 예를 예를 들어

를 만든 당신은 당신의 코드를 표시하지 않는 기대 값을

을 반환하지 않을 수 있습니다 기능, 가치 수단을 반환 추적 기능이 있습니다 3 개 경로의 경우 PARM 1 동등 PARM 2와 동일하지만 PARM가 동일하지 않은 경우 하나 또는 2

function SomeObject foo(integer parm){ 

    if (parm == 1) { 
     return new SomeObject(); 
    } 
    if (parm == 2) { 
     return new SomeObject(); 
    } 
    //What if parm equal something else??? 
} 
관련 문제