0
這段代碼有什麼問題? ..從C#中的對象獲取類型
public void gett(object dato, ref object ty)
{
dato = 1; // <- this compiles
Type t = typeof(dato); //<--- here i Got an error
if (t == typeof(int))
{
ty= 1
}
else
{
ty=""
}
}
我得到一個錯誤「的類型或命名空間名稱‘拿督’找不到(是否缺少using指令或程序集引用?)」
我想把這個VB .NET代碼到C#
Sub getty(ByVal dato As Object, ByRef ty As Object)
If IsDBNull(dato) Then
Select Case ty.GetType.FullName
Case GetType(Integer).FullName
ty = 0
Case GetType(String).FullName
ty = ""
Case GetType(Guid).FullName
ty = New Guid("00000000-0000-0000-0000-000000000000")
Case GetType(DateTime).FullName
Dim da As DateTime = New DateTime(1900, 1, 1)
ty = da
Case Else
ty = ""
End Select
Else
ty = dato
End If
End Sub
感謝
太棒了!謝謝...:S ...我對C#很新穎 – carlos 2010-07-29 23:43:04