C# 초보 질문입니다.
글쓴이: pavil / 작성시간: 금, 2015/10/23 - 4:15오후
HeadFirst C#책에 나오는 연습문제입니다.
생성된 윈도우 창에 있는 버튼을 눌러서 색깔이 계속 변하게 만드는 예제인데요, 질문 내용은 아래와 같습니다.
private void button1_Click(object sender, EventArgs e)
{
while(Visible)
{
for (int i = 254; i >= 0 && Visible; i--)
{
this.BackColor = Color.FromArgb(i, 255 - i, i);
Application.DoEvents();
System.Threading.Thread.Sleep(3);
}
for (int i = 0; i <= 253 && Visible; i++)
{
this.BackColor = Color.FromArgb(i, 255 - i, i);
Application.DoEvents();
System.Threading.Thread.Sleep(3);
}
}
}여기서 for문 조건에 && Visible 이 들어가야 창이 닫히자 마자 프로그램이 종료되더라구요.
&& Visible이 없으면 창이 닫힌뒤 1초정도 더 있어야 프로그램이 완전히 종료됩니다.
while문이 닫히면 for문은 자동적으로 닫히는게 아닌가요? 이해가 잘 되지 않습니다.
Forums:


값을 확인해보세요.
http://codepad.org/
#include <stdio.h> int main(int argc, char** argv) { int i; i=0; printf("%d >= 0 && 0 [ %d]\n", i, i >= 0 && 0); printf("%d >= 0 && 1 [ %d]\n", i, i >= 0 && 1); printf("\n"); i=1; printf("%d >= 0 && 0 [ %d]\n", i, i >= 0 && 0); printf("%d >= 0 && 1 [ %d]\n", i, i >= 0 && 1); printf("\n"); i=2; printf("%d >= 0 && 0 [ %d]\n", i, i >= 0 && 0); printf("%d >= 0 && 1 [ %d]\n", i, i >= 0 && 1); printf("\n"); i=0; printf("%d >= 0 & 0 [ %d]\n", i, i >= 0 & 0); printf("%d >= 0 & 1 [ %d]\n", i, i >= 0 & 1); printf("\n"); i=1; printf("%d >= 0 & 0 [ %d]\n", i, i >= 0 & 0); printf("%d >= 0 & 1 [ %d]\n", i, i >= 0 & 1); printf("\n"); i=2; printf("%d >= 0 & 0 [ %d]\n", i, i >= 0 & 0); printf("%d >= 0 & 1 [ %d]\n", i, i >= 0 & 1); printf("\n"); return 0; } #if 0 0 >= 0 && 0 [0] 0 >= 0 && 1 [1] 1 >= 0 && 0 [0] 1 >= 0 && 1 [1] 2 >= 0 && 0 [0] 2 >= 0 && 1 [1] 0 >= 0 & 0 [0] 0 >= 0 & 1 [1] 1 >= 0 & 0 [0] 1 >= 0 & 1 [1] 2 >= 0 & 0 [0] 2 >= 0 & 1 [1] #endif----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
코드가 비슷하네요.
UNICODE NORMALIZATION FORMS
http://unicode.org/reports/tr15/tr15-33.html
public int quickCheck(String source) {
short lastCanonicalClass = 0;
int result = YES;
for (int i = 0; i < source.length(); ++i) {
char ch = source.charAt(i);
short canonicalClass = getCanonicalClass(ch);
if (lastCanonicalClass > canonicalClass && canonicalClass != 0) {
return NO; }
int check = isAllowed(ch);
if (check == NO) return NO;
if (check == MAYBE) result = MAYBE;
lastCanonicalClass = canonicalClass;
}
return result;
}
public static final int NO = 0, YES = 1, MAYBE = -1;
----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
댓글 달기