我有一个非常简单的程序:
Option Strict On
Imports System
Imports Microsoft.VisualBasic
Module Program
Sub Main(args As String())
Dim birthDate As DateTime = DateTime.Now.AddYears(-1)
Dim dateDifference As DateTime = DateDiff(DateInterval.Month, DateTime.Now, birthDate)
Console.WriteLine(dateDifference.ToString)
Console.ReadLine()
End Sub
End Module
尝试使用DateDiff
给出了错误"未声明DateDiff。由于它的保护级别,它可能无法访问。"我所看到的一切都说DateDiff
应该在Microsoft.VisualBasic
命名空间中。我可以看到,我已经导入了该命名空间。我甚至在解决方案资源管理器中添加了对它的引用。非常令人沮丧,有人请让我知道我做错了什么吗?
答案 0 :(得分:1)
您的代码中存在两个问题
Sub Main(args As String())
Dim birthDate As DateTime = DateTime.Now.AddYears(-1)
Dim dateDifference As Long = DateDiff(DateInterval.Month, DateTime.Now, birthDate)
Console.WriteLine(dateDifference.ToString)
Console.ReadLine()
End Sub
答案 1 :(得分:0)
Option Strict On
Imports System
Imports Microsoft.VisualBasic
Module Program
Sub Main(args As String())
Dim birthDate As DateTime = DateTime.Now.AddYears(-1)
Dim dateDifference As Long = DateDiff(DateInterval.Month, DateTime.Now, birthDate)
Console.WriteLine(dateDifference.ToString)
Console.ReadLine()
End Sub
End Module
这很有效。