gpt4 book ai didi

c# - VB 到 C# 转换 DateAndTime 等效

转载 作者:行者123 更新时间:2023-11-30 13:32:09 25 4
gpt4 key购买 nike

我正在尝试将此 VB block 转换为 C#。

  Public Function AddWorkingDays(ByVal DateIn As DateTime, _
ByVal ShiftDate As Integer) As DateTime
Dim b As Integer

Dim datDate As DateTime = DateIn ' Adds the [ShiftDate] number of working days to DateIn'
For b = 1 To ShiftDate
datDate = datDate.AddDays(1)
' Loop around until we get the need non-weekend day'
If Weekday(datDate) = 7 Then
datDate = datDate.AddDays(2)
End If
Next
Return datDate
End Function

到此为止

public DateTime AddWorkingDays(DateTime DateIn, int ShiftDate)
{
int b = 0;

DateTime datDate = DateIn;
// Adds the [ShiftDate] number of working days to DateIn
for (b = 1; b <= ShiftDate; b++)
{
datDate = datDate.AddDays(1);
// Loop around until we get the need non-weekend day
if (DateAndTime.Weekday(datDate) == 7)
{
datDate = datDate.AddDays(2);
}
}
return datDate;
}

我知道C#中没有DateAndTime我只是把它放在if语句中来完成代码块。我真正的问题是让 IF 语句起作用。我不确定 DateTime.Now.Weekday 是否与之前的 VB 代码中的语句相同。

最佳答案

只需使用 DayOfWeek枚举,例如

datDate.DayOfWeek == DayOfWeek.Saturday

关于c# - VB 到 C# 转换 DateAndTime 等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16087935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com