473,385 Members | 1,846 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,385 software developers and data experts.

Casting Application object in C#

Hi,

I simply want to cast an Application object into the value it's holding. Can
this be done on onew line?

e.g. (int)Application["userCount"] += 1;
or Convert(Application["userCount"]).ToInt32 += 1;
or Int32.Cast(Application["userCount"]) += 1;
I've had to do it as below:

int userCount = (int)Application["userCount"];
Application["userCount"] = ++userCount;

How could this be done more easily?

Many thanks for any answers

Ant
Oct 15 '07 #1
1 2851
More easily? Why is writing two crummy lines of code such a big deal?
Consider using public static int variable in the Global class. Then you can
do:

Global.UserCount ++;

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Ant" wrote:
Hi,

I simply want to cast an Application object into the value it's holding. Can
this be done on onew line?

e.g. (int)Application["userCount"] += 1;
or Convert(Application["userCount"]).ToInt32 += 1;
or Int32.Cast(Application["userCount"]) += 1;
I've had to do it as below:

int userCount = (int)Application["userCount"];
Application["userCount"] = ++userCount;

How could this be done more easily?

Many thanks for any answers

Ant
Oct 15 '07 #2

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

Similar topics

2
by: Angelos Karantzalis | last post by:
Hi guys, I'm trying to load a class instance dynamically, and then cast it to it's base type so I can use it in my app. More specifically, I'm dynamically instantiating a...
4
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A...
9
by: Kurt | last post by:
Hi I was trying to get this VB type code to work in C Sub SetColumns_Example( Dim ol As Outlook.Applicatio Dim MyFolder As MAPIFolde Dim itms As Item Dim itm As Objec Dim dtmStart As Date,...
7
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b;...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
0
by: Greg Conely via .NET 247 | last post by:
I am creating a application that will be using plugins. I am doing this so that when I want to let this application work with another type of dbase system, I only have to write\install one plugin,...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
13
by: DaTurk | last post by:
Hi, This is a question brought about by a solution I came up with to another question I had, which was "Dynamic object creation". So, I'm curious if you can dynamically cast an object. If you...
7
by: S. Lorétan | last post by:
Hi guys, Sorry for this stupid question, but I don't know why it isn't working. Here is my (example) code: namespace Test { class A { public string Label1; }
11
by: Frederic Rentsch | last post by:
Hi all, If I derive a class from another one because I need a few extra features, is there a way to promote the base class to the derived one without having to make copies of all attributes? ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.