PC Review


Reply
Thread Tools Rate Thread

Casting Application object in C#

 
 
=?Utf-8?B?QW50?=
Guest
Posts: n/a
 
      15th Oct 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      15th Oct 2007
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting and iteration in object of type object eliassal Microsoft Dot NET 2 8th Jan 2010 05:59 PM
casting from object Tony Johansson Microsoft C# .NET 0 23rd Sep 2008 10:11 PM
issue type casting derived object to base object Microsoft C# .NET 2 7th Sep 2007 07:26 AM
Object casting =?Utf-8?B?bWdvbnphbGVzMw==?= Microsoft C# .NET 2 23rd May 2006 02:48 PM
casting an object =?Utf-8?B?cm9kY2hhcg==?= Microsoft VB .NET 6 7th Feb 2005 02:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 AM.