내 코드를 더 빨리 만들려고 노력 중이며 If-else 및 If 또는 else가 많이 있습니다. 스위치 케이스가 5 개 이상인 경우 스위치 케이스가 더 빠르다는 것을 안다. 따라서 if-else
과 if-or
은 얼마나 빨랐습니까?if else if if 또는 vs switch case
if (item.Datum.Substring(5, 5) == "06-20" || item.Datum.Substring(5, 5) == "06-21")
{
Something
}
else if item.Datum.Substring(5, 5) == "06-22" || item.Datum.Substring(5, 5) == "06-23")
{
Something
}
또는
if (item.Datum.Substring(5, 5) == "06-20")
{
Something
}
else if (item.Datum.Substring(5, 5) == "06-21")
{
Something
}
else if (item.Datum.Substring(5, 5) == "06-22")
{
Something
}
else if (item.Datum.Substring(5, 5) == "06-23")
{
Something
}
또는 난 그냥 스위치 케이스와 함께 갈 것인가? 어떤 경우에는
switch(item.Datum.Substring(5, 5))
{
case "06-20", "06,21":
Something
break;
case "06-22", "06,23":
Something
break;
}
http://stackoverflow.com/questions/395618/is-there-any-significant-difference-between-using-if-else-and-switch-case -in-c – DarkBee
[어느 쪽이 더 빠릅니까?] (http://ericlippert.com/2012/12/17/performance-rant/) –
다른 부분을 제외하고는 '하위 문자열'을 여러 번 호출하지 마십시오! –