Я создал функцию, которая использует метод расчета для вычисления суббот и воскресений. Я не проверял это до смерти. В ответе @ p.campbell я проверил производительность и метода вычисления (см. Ниже), и метода итерации, результат в миллисекундах для 10 000 вызовов составил.
Расчет: 7
Итерация: 39
Надеюсь, это поможет.
Dave
Dim month As Integer = 12
Dim year As Integer = 2011
'Calculate the Start and end of the month
Dim current As New DateTime(year, month, 1)
Dim ending As DateTime = current.AddMonths(1)
'Ints to hold the results
Dim numSat As Integer = 0
Dim numSun As Integer = 0
'Numbers used in the calculation
Dim dateDiff As Integer = (ending.Date - current.Date).Days
Dim firstDay As DayOfWeek = current.DayOfWeek
'Figure out how many whole weeks are in the month, there must be a Sat and Sunday in each
' NOTE this is integer devision
numSat = dateDiff / 7
numSun = dateDiff / 7
'Calculate using the day of the week the 1st is and how many days over full weeks there are
' NOTE the Sunday requires a bit extra as Sunday is value 0 and Saturday is value 6
numSat += If((firstDay + (dateDiff Mod 7)) > (DayOfWeek.Saturday), 1, 0)
numSun += If(((firstDay + (dateDiff Mod 7)) > (DayOfWeek.Saturday + 1)) Or (firstDay = DayOfWeek.Sunday And (dateDiff Mod 7 = 1)), 1, 0)
'Output the results
Console.WriteLine("Sats: " & numSat)
Console.WriteLine("Suns: " & numSun)
Console.ReadLine()