Tag Archives: string

Use XML literals in C#

Visual Basic lets you include XML literals directly in your code as in the following example. Dim employees As XElement = <employees> <employee firstname=”Terry” lastname=”Pratchett”/> <employee firstname=”Glen” lastname=”Cook”/> <employee firstname=”Tom” lastname=”Holt”/> <employee> <firstname>Rod</firstname> <lastname>Stephens</lastname> </employee> </employees> Unfortunately, C# doesn’t allow … Continue reading

Posted in strings, XML | Tagged , , , , , , , | Leave a comment

See how much text fits in a rectangle in C#

This program determines how much text fits in the left PictureBox and draws it. It then draws the remaining text in the right PictureBox. If you change the form’s size, the size of the PictureBox controls change so how much … Continue reading

Posted in fonts, graphics, strings | Tagged , , , , , , , , , , , , , , , , , | Leave a comment

Compare the speeds of different methods for string concatenation in C#

There are several ways you can perform string concatenation in C#. For example, you can use += to add text to an existing string, you can use string.Concat, and you can use the StringBuilder class. This example compares the performance … Continue reading

Posted in performance, strings | Tagged , , , , , , , , , , , | 1 Comment