[英]converting dates things from visual basic to c-sharp
So as an excercise in utility i've taken it upon myself to convert one of our poor old vb .net 1.1 apps to C# .net 4.0. 因此,作为一个实用的练习我已经把它自己转换为我们可怜的旧的vb .net 1.1应用程序之一转换为C#.net 4.0。
I used telerik code conversion for a starting point and ended up with ~150 errors (not too bad considering its over 20k of code and rarely can i get it to run without an error using the production source) many of which deal with time/date in vb versus c#. 我使用了telerik代码转换作为一个起点,最终得到了大约150个错误(考虑到它的代码超过20k,并且很少能让它在没有使用生产源的错误的情况下运行),其中很多都处理时间/日期在vb与c#中。
my question is this how would you represent the following statement in VB 我的问题是你如何在VB中表示以下语句
If oStruct.AH_DATE <> #1/1/1900# Then
in C#? 在C#? The converter gave me 转换器给了我
if (oStruct.AH_DATE != 1/1/1900 12:00:00 AM) {
which is of course not correct but I cannot seem to work out how to make it correct. 这当然不正确,但我似乎无法弄清楚如何使其正确。
if (oStruct.AH_DATE != new DateTime(1900, 1, 1){
You may try this construct : 你可以试试这个结构:
if ( DateTime.Compare(oStruct.AH_DATE, new DateTime(1900, 1, 1)) == 0 )
{
// your code here
}
Here is a reference how to compare DateTimes in .NET - DateTime.Compare Method 以下是如何在.NET中比较DateTimes的参考 - DateTime.Compare方法
Note: Comparing two dates like integers may lead you to wrong results. 注意:比较两个日期(如整数)可能会导致错误的结果。 Because, date-time structure in .NET has its specific properties. 因为.NET中的日期时间结构具有其特定属性。 I would always try to be attentive when comparing two dates, and always choose DateTime.Compare
to be on a safer side. 在比较两个日期时,我总是会注意细心,并且总是选择DateTime.Compare
以使其处于更安全的一面。
这应该工作:
if (oStruct.AH_DATE != DateTime.Parse("1/1/1900"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.