Ağustos 12, 2010

Asp.Net - CType TryCast DirectCast

CType V.Basic runtime helper kullanır, DirectCast kullanmaz.DirectCast bu yüzden daha hızlı çalışır.CType ile aralarındaki fark budur. Hata durumunda ikiside InvalidCastException hatası döndürür.


Directcast -> Dönüştürülen nesne doğru tipte değilse hata dönderecektir.
TryCast ->Dönüştürülen nesne doğru tipte değilse hata döndermez,null değer döndürür.TryCast Try Catch'in catch'siz haline benzemektedir.

TryCast(Page.Form.FindControl("Label1"), HiddenField)  // Label HiddenField Hata döndermez
DirectCast(Page.Form.FindControl("Label1"), HiddenField)  // Hata döndürür.

Hiç yorum yok:

Yorum Gönder

System.Text.Json.JsonException hatası - cycle or if the object depth is larger than the maximum allowed depth of 32.

 Eğer .net'te aşağıdaki hatayı alıyorsanız; " A possible object cycle was detected which is not supported. This can either be due t...