Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         void GetCurveParams(XmlElement element)
         {
             //Get curve parameters using a bit of XPath, order using LINQ
             //XPath 1.0 doesn't support regex - should match all attributes with names matching "c[0-9]+"
             var curveParams = element.SelectNodes("@*[starts-with(name(), 'c') and string(number(substring(name(),2))) != 'NaN']")
                 .OfType()
                 .OrderBy(attr => attr.Name);

             //Cast the values to float and convert to an array
             CurveParams = curveParams
                 .Select(attr => float.Parse(attr.Value))
                 .ToArray();
         }