我想下面的VB代码转换成C#VB.NET到C#转换错误
VB代码:
Public Class function_library
Public Shared Function handle_dbnull(ByVal value As Object, ByVal _type As System.Type) As Object
Select Case _type.ToString
Case GetType(Date).ToString, GetType(DateTime).ToString
If Not IsDBNull(value) Then
Return value
Else
Return New DateTime(0)
End If
End Select
Return value
End Function
End Class
目前的C#实现我的是:
public static object HandleDBNull(object value, Type _type)
{
switch (Type.GetTypeCode(_type))
{
case typeof(DateTime?).ToString(): // This produces a cannot convert string to System.TypeCode error
if ((!ReferenceEquals(value, DBNull.Value)))
{
return value;
}
else
{
return null;
}
}
}
我曾尝试使用其他Stackoverflow问题中提供的Web链接,以及VB到C#的在线转换器,但都似乎没有帮助解决我的问题。
什么我可能是做错了或者怎样去解决这一问题将是巨大的任何意见,
卢克
什么是错误?这对于这个问题至关重要。不要将它隐藏在代码注释 –
typeof(DateTime?)。ToString():为什么会有?在DateTime后标记 –
[嗯...](https://stackoverflow.com/q/44671596/579895) – Pikoh