问题描述
我在 vb 中有以下代码 -
I have the following code in vb -
tAvailableDate = DateAdd("d", 21, Format(Now, gDATEFORMAT))
我正在尝试将其转换为 C#.
I am attempting to convert this into C#.
到目前为止我已经转换了这个 -
I have converted this so far -
tAvailableDate = DateAdd("d", 21, Format (DateTime.Now, Global.gDATEFORMAT));
但我找不到 DateAdd()
或 Format()
功能的替代品.
But I cannot find a replacement for the DateAdd()
or Format()
feature.
有什么想法吗?谢谢.
推荐答案
DateAdd
是一种旧的 VB6 方法,为了向后兼容,它被带入了 VB.NET.如果您在 C# 项目中包含 Microsoft.VisualBasic
命名空间,您也可以让它在 C# 中工作,但我不建议在 C# 或 VB.NET 中使用该方法.以下是您应该如何做(它也更容易阅读):
DateAdd
is an old VB6 method that was carried over into VB.NET for backwards compatibility. You could get it to work in C# as well if you included the Microsoft.VisualBasic
namespace in your C# project, but I wouldn't recommend using the method in C# or VB.NET. Here's how you should be doing it (it's easier to read too):
tAvailableDate = DateTime.Now.AddDays(21);
这篇关于将 DateAdd 和 Format 代码从 VB6 转换为 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!