VB to C#how does DirectCast convert?

  • Thread starter Thread starter Andrea Williams
  • Start date Start date
A

Andrea Williams

I have this line in VB and I need to convert it to C#:


Return DirectCast(HttpContext.Current.Session("LastException"), Exception)

I've been unable to find an equivelent to DirectCast and I can't seem to get
Convert.ChangeType to work for me either. This is what I have t the moment:



return Convert.ChangeType(HttpContext.Current.Session["LastException"],
Exception);



Any idea what I'm doing wrong? Am I using the wrong function, not loading
it correctly?



Any help would be appreciated!

Andrea
 
That worked!!! thank you so much!


bruce barker said:
return (Exception) HttpContext.Current.Session["LastException"];


Andrea Williams said:
I have this line in VB and I need to convert it to C#:


Return DirectCast(HttpContext.Current.Session("LastException"), Exception)

I've been unable to find an equivelent to DirectCast and I can't seem to get
Convert.ChangeType to work for me either. This is what I have t the moment:



return Convert.ChangeType(HttpContext.Current.Session["LastException"],
Exception);



Any idea what I'm doing wrong? Am I using the wrong function, not loading
it correctly?



Any help would be appreciated!

Andrea
 
Back
Top