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

C#-APP:Getting variable type then use it to cast a string

71
Hi, can anyone help me on this snippet.
I want to improve the casting to be dependent on the variable it will be assigned to, is there a way? (Please see source code below)

I tried the "typeof" but it is not the right thing to use.
Hope anyone can help me on this.
Thanks a lot in advance.

Expand|Select|Wrap|Line Numbers
  1. switch (nodeName.Name)
  2.             {
  3.                     //header elements
  4.                 case ConstantVariables.ELEM_MSGID:
  5.                     _messageID = Convert.ToUInt32(nodeName.InnerText);
  6.                     break;
  7.                 case ConstantVariables.ELEM_GPBAL:
  8.                     GameState.PlayerState.Player.CurrentBalance = Convert.ToInt64(nodeName.InnerText);
  9.                     break;
  10.  
  11.                 default:
  12.                     nodeName.ParentNode.RemoveChild(nodeName);
  13.                     break; 
  14.             }
  15.  
Dec 3 '08 #1
2 1138
PRR
750 Expert 512MB
@dantz
I guess you got it right now.... though look for
InvalidCast
Format and possibly overflow exception..
Dec 3 '08 #2
dantz
71
thanks for the reply.
i guess this solution is the simplest one..I better stick to it..
Dec 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
8
by: Groups User | last post by:
C allows type casting in which a variable is converted from one type to another. Does C (whatever standard) allow the type of a variable to change, within a statement, avoiding the conversion?...
26
by: Michael McGarry | last post by:
Hi, I am pretty sure this is not possible, but maybe somehow it is. Given a variable, can I tell what type it is at runtime? Michael
11
by: Jim H | last post by:
I am trying to go through my Outlook (2003) address book. The code goes through the Items list and prints all the last names but after it hits 114 (out or 126 contacts) I get a "sepcified cast is...
3
by: cody | last post by:
why foreach does always have to declare a new variable? I have to write foreach (int n in array){} but Iam not allowed to write: int n=0; foreach (n in array){}
6
by: melanieab | last post by:
Hi, Easy question. It seems to me that I'm following the examples correctly, but apparently I'm not. I'm trying to retrieve the data from a row called "row" and a column called "File". This is...
9
by: Phil | last post by:
I have a custom class that has been assigned to a variable and worked with, I now need to cast this class as a different class, which is in a separate assembly, not currently in the project. ...
11
by: JohnR | last post by:
I'm trying to find a way to create a variable of a given type at runtime where I won't know the type until it actually executes. For example, dim x as object = "hi" x is declared as an object...
2
by: =?iso-8859-1?B?RulybmFz?= | last post by:
Hello all, Imagine that I have this: string myType = "FormProducts"; // FormProducts is the product's form... then, I'd like to create a variable of type "FormProducts" (or other type that...
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.