about return syntax in c#
<p>I wonder why I need to put return syntax twice time in below code,</p>

<pre><code>public string test(){
 bool a = true;
 if(a){
   string result = "A is true";
 }else{
   string result = "A is not true";
 }

  return result;
}
</code></pre>

<p>it makes an error that say The name 'result' does not exist in the current context.</p>

<p>but either way, there is the result variable. Hmm..</p>

<p>So I changed the code like this,</p>

<pre><code>public string test(){
 bool a = true;
 if(a){
   string result = "A is true";
   return result;
 }else{
   string result = "A is not true";
   return result;
 }
}
</code></pre>

<p>Then it works. Is it correct using like this?</p>

<p>please advice me,</p>

<p>Thank you!</p>
