else if(Y=='n'){...}
로 else{if(Y== 'n'){...}}
리팩토링 좋은 것입니다. 당신이 class
를 정의 할 때 당신은 다음과 같이 중괄호 안에 코드 블록을 정의 중괄호 내
public class MyClass
{
}
것 "이 그 범위에"로 간주됩니다. 예를 들어 : IF
문장의 경우
public class MyClass
{
// This method is in the scope of MyClass
public void MyMethod()
{
// This variable is in the scope of MyMethod.
// It is only accessible from within this method because that is where
// it is defined.
string myString = "Hello Method.";
}
// This variable is in the scope of MyClass.
// It is accessible within MyClass, including all methods that are also in scope
// of MyClass
public string myGlobalString = "Hello Global.";
}
, 그들은 블록 일련의 문장입니다 만 (당신은 예를 들어 클래스에 IF
문을 사용할 수없는) 방법의 범위에 포함 할 수 있습니다. 코드는 명령문에서 제공 한 경로 중 하나를 이동할 수 있습니다. 예 :
public class MyClass
{
public void MyMethod(string myString)
{
if (myString == "Hello")
{
// Read like English. "If variable myString equals the value 'Hello', then do this code within this block."
}
else if (myString == "Goodbye")
{
// "...or else if variable myString equals the value 'Goodbye', then do this code within this block instead.
}
else if (myString == "Good Morning")
{
// "...or else if variable myString equals the value 'Good Morning', then do this code within this block instead.
}
else
{
// "...or else do this code if variable myString does not match any of the above code statements.
}
// You are not required to include "else" or even "else if". You could just do a single IF statement like this:
if (myString == "hi)
{
// "If variable myString equals the value 'hi' then do this, otherwise do nothing."
}
}
}
그는 무엇을 변경 했습니까? – unknown
아, 태그 !!!! – unknown
나는 초심자이며 배우고 있음을 이해합니다. 당신이 염두에두고 싶은 한 가지는 일관된 형식을 유지하는 것입니다. 왼쪽 중괄호'{'를 사용하여 새 블록을 시작할 때마다 모든 추가 행을 들여 씁니다. 일치하는 오른쪽 중괄호 {}'에 도달 할 때까지 모든 행을 계속 유지해야합니다. 그렇게 했더라도 코드에 문제가 있음을 쉽게 알 수있었습니다. 중괄호는 일치하지 않으며, 문장을 포함하지 않아야합니다. Visual Studio는 문장을 따라 가면 들여 쓰기를 도와줍니다. –