SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 264 | Next

Scott Klein

"Professional LINQ"

AddAnnotation(ano1);
textBox1.Text = root.ToString();
TestAnnotation ano2 = root.Annotation();
textBox1.Text = ano2.Val1.ToString();
When you run this code, the text box should display the value 500.
158
Chapter 8: Advanced LINQ to XML Programming Topics
Of course, annotations can be of any type, so the preceding code could simply have been written
as follows:
XElement root = new XElement("Root", "scott");
root.AddAnnotation(500);
What happens if you want to add an annotation of another type? Fortunately, you don??™t need to create
a new annotation class. The following is an example that uses the same original annotation class to add
another annotation type of string, as shown by the highlighted code. It does that by creating a new public
method of the same name as the original method:
public class TestAnnotation
{
private int val1;
private string val2;
public int Val1 { get { return val1;} set { val1 = value;}}
public string Val2 { get { return val2;} set { val2 = value;}}
public TestAnnotation(int val1)
{
this.


Pages:
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6