Day
속성은 주, 아니 하루 달의 날입니다. DateOfWeek 열거 형과 정확하게 비교하려면 Date 개체의 DayOfWeek
속성을 사용합니다.
Dim dates(Nights) as Date
For i As Integer = 0 To Nights
If dates(i).DayOfWeek = DayOfWeek.Saturday Or dates(i).DayOfWeek = DayOfWeek.Sunday Then
BaseRate += (BaseRate * dclWeekendSurcharge)
End If
Next
개념
아래의 샘플 코드와 체류 기간에 대한 비율 계산으로 변환 할 수 있습니다 :
는
Imports System
Imports System.Collections.Generic
Dim nightlyRate as Decimal = 60 '$60/night
Dim weekendSurcharge as Decimal = 0.1 '10% higher
System.Console.WriteLine("$60 = ${0}", GetTotal(Date.Parse("1/1/2015"), Date.Parse("1/2/2015"), nightlyRate, weekendSurcharge))
System.Console.WriteLine("$120 = ${0}", GetTotal(Date.Parse("1/1/2015"), Date.Parse("1/3/2015"), nightlyRate, weekendSurcharge))
System.Console.WriteLine("$186 = ${0}", GetTotal(Date.Parse("1/1/2015"), Date.Parse("1/4/2015"), nightlyRate, weekendSurcharge))
Function GetTotal(startDay as Date, endDay as Date, baseRate as Decimal, weekendSurcharge as Decimal) as Decimal
Dim total as Decimal = 0
Do While startDay < endDay
total += baseRate
If startDay.DayOfWeek = DayOfWeek.Saturday Or startDay.DayOfWeek = DayOfWeek.Sunday Then
total += (baseRate * weekendSurcharge) 'Assume surchage is a multiplier, not a dollar rate
End If
startDay = startDay.AddDays(1)
Loop
Return total
End Function
이는 출력 :
$60 = $60 '1 night, no weekend
$120 = $120 '2 nights, no weekend
$186 = $186.0 'This is with the 10% multiplier since 1/3 is a weekend
해야 하는가'날짜 (i)를. = DayOfWeek.Saturday'은 (i) .Day = DayOfWeek.Saturday'일까요? 너는 잃어버린 것 같아. 토요일에있는 날. –
그건 내 부분에서 오타였다. 코드에서 수정되었지만 여전히 올바르게 실행되지 않습니다. – user3440204