From the course: .NET Essentials: LINQ for XML
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Use SetValue to set with non-string data - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Use SetValue to set with non-string data
- [Instructor] Earlier in this chapter, we looked at the value property. It is read-write property of type string. So that means that if you have a variable, like I do here on line nine, I have a decimal variable, and I would like to assign that to the value property, like I'm doing here on line 14 and 13, I can't do it directly. You can see that this is a type string. When I hover over this error, I see that it can not implicitly convert type decimal to string. So as a programmer, you know how to deal with this. You would convert this to a string, in one way or another. Here's a simple way of doing that. But if you don't want to go through this process of converting it to a string, there is the set value method that does that automatically for you. So let me comment out these two again. And like it the Syntech is set value. It takes an object as a parameter. And essentially what this method does is it calls two…
Contents
-
-
-
-
(Locked)
Get an element from XML2m 33s
-
(Locked)
Get an attribute from XML1m 25s
-
(Locked)
Get nodes when using schema namespace3m 32s
-
(Locked)
Get single or multiple elements2m 27s
-
(Locked)
Get child element1m 12s
-
(Locked)
Get child elements1m 58s
-
(Locked)
Use Descendants() to recurse child elements52s
-
(Locked)
Get attributes51s
-
(Locked)
Read element and attribute values1m 32s
-
(Locked)
Change element and attribute values1m 36s
-
(Locked)
Use SetElementValue to add, remove, and modify child elements1m 37s
-
(Locked)
Use SetValue to set with non-string data1m 4s
-
(Locked)
-
-
-