내 코드에서 Print
을 자주 호출한다고 가정합니다.함수를 사용한 변수 최적화
글로벌 변수 또는 로컬 변수로 CurrentPosition
을 선언해야합니까?
빠른 버전을 알고 싶습니다.
옵션 A :
int CurrentPosition = 0;
void Print(string key, int conc, int col, byte _color) {
if (col <= cMax ? col >= cMin : false) {
if (CurrentRows.TryGetValue(key + "#" + conc.ToString(), out CurrentPosition)) { //Row is in the vieport
grid.GetCell(CurrentPosition, col).Presenter.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0));
}
}
}
옵션 B :
void Print(string key, int conc, int col, byte _color) {
int CurrentPosition = 0;
if (col <= cMax ? col >= cMin : false) {
if (CurrentRows.TryGetValue(key + "#" + conc.ToString(), out CurrentPosition)) { //Row is in the vieport
grid.GetCell(CurrentPosition, col).Presenter.Background = new SolidColorBrush(Color.FromRgb(255, 255, 0));
}
}
}
왜'col <= cMax? '를 사용합니까? col> = cMin : false> 대신'col <= cMax && col> = cMin'? '&&'는 단락 할 것이다. –
'out' 매개 변수로 전달되는 경우 왜 변수에'= 0'을 할당합니까? 그 '0'덮어 씁니다. –
여기가 작은 세부 사항이라고 생각합니다. 어쨌든'int' 타입의 기본값은 0입니다. 이것은 out 매개 변수없이 모든 경우에 중복됩니다. – ZenLulz