你如何将这段代码(在 Visual Basic 上)翻译成 C#
For m = 1 To 12
Dim daysInMonth = curCulture.Calendar.GetDaysInMonth(year, m)
Dim firstMonthDate = New Date(year, m, 1)
Dim daysBefore = (7 + (firstMonthDate.DayOfWeek - firstYearDate.DayOfWeek)) Mod 7
Dim daysBehind = (tblCalendar.Columns.Count - 2) - (daysBefore + daysInMonth) - 1
Dim monthDays = From d In Enumerable.Range(1, daysInMonth) Select New With {.Day = d.ToString}
Dim emptyDaysBefore = From d In Enumerable.Range(1, daysBefore) Select New With {.Day = ""}
Dim emptyDaysAfter = From d In Enumerable.Range(1, daysBehind) Select New With {.Day = ""}
Dim montos = From d In Enumerable.Range(1, 2) Select New With {.Day = "0"}
Dim monthName = curCulture.DateTimeFormat.GetMonthName(m)
Dim allFields = ({New With {.Day = monthName}}.
Union(emptyDaysBefore).
Union(monthDays).
Union(emptyDaysAfter).
Union(montos).
Select(Function(d) d.Day)
).ToArray
tblCalendar.Rows.Add(allFields)
Next
我不能简单地通过这样做找到联合方法:
for (int _m = 1 ; _m <= 12; _m++) {
int _daysInMonth = _currentCulture.Calendar.GetDaysInMonth(_selYear, _m);
DateTime _firstMonthDate = new DateTime(_selYear, _m, 1);
int _daysBefore = (7 + (_firstMonthDate.DayOfWeek - _firstDateOfYear.DayOfWeek)) % 7;
int _daysBehind = (_tableCalendar.Columns.Count) - (_daysBefore + _daysInMonth) - 1;
var _monthDays = from d in Enumerable.Range(1, _daysInMonth) select new { Day = d.ToString() };
var _emptyDaysBefore = from d in Enumerable.Range(1, _daysBefore) select new { Day = "" };
var _emptyDaysAfter = from d in Enumerable.Range(1, _daysBehind) select new { Day = "" };
string _monthName = _currentCulture.DateTimeFormat.GetMonthName(_m);
var _allFields = (new {
Day = _monthDays
});
}