Algorithm
-
또또 지나가다 본 코드..!! C# 더블쿼션마크 DOUBLE QUESTION MARKAlgorithm 2009. 9. 22. 10:21
return (numOne != null ? numOne : (numTwo != null ? numTwo : 10)); 삼항연산자를 두번 섰다 !!! 이런 크래이티브한 일이 있다니~!! 그런데 여기서 더 더 크래이티브하것이~!! 있었다는데 바로 더블쿼션마크(물음표2개) 참고 블러거의 말을 붙여오자면 But with the double question mark operator we can do this: return ((numOne ?? numTwo) ?? 10); As you can see, the double question mark operator returns the first value that is not null. C# 일년가까이 해오면서 더블 쿼션 마크는 처음봄니다? 중수로 가는 길은 멀고도..
-
지나가다 본 코드2Algorithm 2009. 7. 20. 22:49
//ListBox lb = sender as ListBox; //ShoppingCartItem scItem = lb.SelectedItem as ShoppingCartItem; //LongDescriptionLabel.Text = scItem.LongDescription.ToString(); LongDescriptionLabel.Text = ((sender as ListBox).SelectedItem as ShoppingCartItem).LongDescription.ToString(); 이런 코드 크레이티브하다 넘좋아~! - 참고 Programming .Net 3.5 by Jesse Liberty and Alex Horovitz. 코드를 줄일려고 이런 책도 검색 해 두었다. 참고~! 숏코딩이란다~! 저자..
-
[C} algorithm 메크로 관련 알고리즘Algorithm 2009. 4. 29. 01:54
if ((a==10) || (a==20)) { ... } if (abs(15-a) == 5) { ... } 비교될 두 수의 중점과 비교할 수의 차에 대한 절대값을 한 번만 비교하면 된다. abs 함수가 절대값을 구하므로 abs(15-a)는 abs(a-15)로 써도 결과는 동일하다. 이 예와 같이 단순 변수와 상수를 비교할 때는 큰 차이가 없지만 함수 호출 결과를 비교할 때는 함수를 두 번 호출할 것을 한 번만 호출해도 되는 큰 차이가 발생한다. 이번에는 범위를 점검하는 조건문을 만들어 보자. a가 10~50사이에 있는지 검사하고자 할 때도 abs 함수를 사용할 수 있다. if ((a>10) && (a