"Munsifali Rashid" <mun-news@**RemoveToReply**@cordlessmouse.co.uk> wrote in
message news:42728c13$0$2054$db0fefd9@news.zen.co.uk...[color=blue]
> Good to hear you're making the jump to C#
>
> You need to cast your class back to the correct type, as it is boxed when
> you store it into the session. To do this, change the last two lines of[/color]
Note: Your answer was correct - but this is NOT boxing.
Just to clarify:
Boxing is the conversion of a value type (such as int, double, etc) to an
object class ("boxing" the value inside an object).
--
Adam Clauss
cabadam@tamu.edu
[color=blue]
>
> datafunct.sessioninfo mysession = (datafunct.sessioninfo)
> Session.Contents["sessioninfo"];
>
> ie. You don't need to create a new instance of the class first.
>
> Hope this helps,
>
> Mun
>
> --
> Munsifali Rashid
>
http://www.munit.co.uk/blog/
>
>
>
> "Fred Nelson" <fred@smartybird.com> wrote in message
> news:OPvr3DPTFHA.3636@TK2MSFTNGP14.phx.gbl...[color=green]
>> Hi:
>>
>> I'm a VB.NET programmer who is attempting to write my first C# web
>> application. Everything is going VERY well however I have hit one snag:
>>
>> In the VB.NET world we can easily save classes in session variables. I'm
>> hoping that I can do the same thing in C# however I'm doing something
>> wrong
>> since I get the error:
>>
>> Cannot implicitly convert type 'object' to 'datafunct.sessioninfo'
>>
>> here is my class in a class library called datafunct:
>>
>> public class sessioninfo
>> {
>> public int memberid;
>> public string membername;
>> }
>>
>> I can load the session variable with:
>>
>> datafunct.sessioninfo mysession = new datafunct.sessioninfo();
>> mysession.memberid = 15;
>> mysession.membername = "Fred Smith";
>> Session.Contents["sessinfo"] = mysession
>>
>> I'm not get the error: Cannot implicitly convert type 'object' to
>> 'datafunct.sessioninfo' with the second line of code below:
>>
>> datafunct.sessiononinfo mysession = new datafunct.sessioninfo();
>> mysession = Session.Contents["sessinfo"];
>>
>> Any help for this "newby" question would be GREATLY appreciated!
>>
>> Thanks very much for your help!
>>
>> Fred
>>
>>[/color]
>
>[/color]