473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Session Variable and Casting

I am new to Asp world and I have a doubt as follows. I
have a class called objTranslator, which I declare and
initiate global.asax as follows.

Session_Start
csTranslator.objTranslator sesObjTranslator= new
objTranslator();
Session["sesTranslator"]=sesObjTranslator;
----------------
Now in WebForm

private csTranslator.objTranslator webTranslator;

In Page Load

if(Session["sesTranslator"]!=null)
webTranslator=(objTranslator)Session["sesTranslator"];

The question is why do I have to explictly cast the
session variable sesTransilator to objTransilator while it
is holding a reference to sesObjTranslator.

So actually what type is the session variable.

In VB.Net one can directly use

webTranslator=Session("sesTranslator")

What is the difference here?

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #1
1 4987
The Session[] object is a collection of objects. That way it can hold any
type of class (since all are derived from object). By casting, you are
telling the compiler that you know exactly what type of object that should
be. VB doesn't have as advanced a pre-compile type checking system
(allowing for more 'sloppy' code).

-Noah Coad
Microsoft MVP & MCP [.NET/C#]
"Rajesh Abraham" <ch******@hotmail.com> wrote in message
news:00****************************@phx.gbl...
I am new to Asp world and I have a doubt as follows. I
have a class called objTranslator, which I declare and
initiate global.asax as follows.

Session_Start
csTranslator.objTranslator sesObjTranslator= new
objTranslator();
Session["sesTranslator"]=sesObjTranslator;
----------------
Now in WebForm

private csTranslator.objTranslator webTranslator;

In Page Load

if(Session["sesTranslator"]!=null)
webTranslator=(objTranslator)Session["sesTranslator"];

The question is why do I have to explictly cast the
session variable sesTransilator to objTransilator while it
is holding a reference to sesObjTranslator.

So actually what type is the session variable.

In VB.Net one can directly use

webTranslator=Session("sesTranslator")

What is the difference here?

Thanks,

Rajesh Abraham Chacko

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you...
0
by: Rajesh Abraham | last post by:
I am new to Asp world and I have a doubt as follows. I have a class called objTranslator, which I declare and initiate global.asax as follows. Session_Start csTranslator.objTranslator...
13
by: dee | last post by:
Hi My code complies the following line: Session("passed") = 1 but puts wiggly error line under the second Session("passed") in the following expression: Session("passed") = Session("passed") +...
7
by: tshad | last post by:
Can I directly access an object member from an object I have saved as a session variable? I am carrying a session variable for my user information as separate session vaiables for each...
5
by: Diffident | last post by:
Hello All, I have a 2-dimensional array that I am storing as a session variable. I have no idea on how I can cast the session variable back to 2-dimensional array. Any pointers? Reference...
2
by: =?Utf-8?B?R2Vvc3Ns?= | last post by:
Dear All, I try to change a master page in the OnPreInit in a asp.net page. (Session variable is guaranteed to have been assigned) protected override void OnPreInit(EventArgs e){ if...
4
by: AndreH | last post by:
Good day, I have the a bit of an issue with retrieving an object from php's session. I set a session variable "user" from the class User as follows: $user = new User(); // ... do some stuff...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.