|
 |
aspx thread: Casting an XML attribute as an int?
Message #1 by "Oliver, Wells" <WOliver@l...> on Tue, 5 Nov 2002 13:58:59 -0800
|
|
This results in an invalid cast:
objAttr = childNode.Attributes["level"];
levelAccess = objAttr.Value.ToString();
return (int)levelAccess;
It's odd, because the level attribute is, e.g.: 'level="1"'. The compiler
tells me "Cannot convert type 'string' to 'int'". Why?! :)
Wells Oliver
Web Applications Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
Message #2 by "Mark Struck" <struckm@a...> on Tue, 5 Nov 2002 16:23:00 -0600
|
|
Oliver,
You can't cast a string to an integer. You need to use the Convert helper
class instead.
Using your code as an example,
return Convert.ToInt32(levelAccess);
Mark
-----Original Message-----
From: Oliver, Wells [mailto:WOliver@l...]
Sent: Tuesday, November 05, 2002 3:59 PM
To: ASP.NET
Subject: [aspx] Casting an XML attribute as an int?
This results in an invalid cast:
objAttr = childNode.Attributes["level"];
levelAccess = objAttr.Value.ToString();
return (int)levelAccess;
It's odd, because the level attribute is, e.g.: 'level="1"'. The compiler
tells me "Cannot convert type 'string' to 'int'". Why?! :)
Wells Oliver
Web Applications Programmer
Leviton Voice & Data
xxx-xxx-xxxx
http://www.levitonvoicedata.com
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
|
|
 |