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
 
return (Exception) HttpContext.Current.Session["LastException"];
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top