My.Settings is a very useful new aspect of the .NET Framework 2.0. It is worthwhile to view this element of the My extensions in context, along with its other brethren. In fact, if there's an underappreciated workhorse in the new Visual Studio 2005 (and its equally new companion, the .NET Framework 2.0) it's got to be the many Visual Basic language extensions that fall under the My hierarchy in that environment. You can use My constructs for an amazing array of activities, as you'll shortly see.
A brief run-down on what this do-it-all namespace can do includes the following:
A good example of what's possible may be revealed by exploring the My.Computer.FileSystem and other related classes, which some experts describe as a "speed-dial" for the .NET framework. For example, whereas some programmers may choose to use IO.StreamReader and its sr.ReadToEnd function to copy the contents of a text file into a string (which requires at least three lines of code), a single assignment statement using My will also do the job -- namely:
Contents = My.Computer.FileSystem.ReadAllText("c:\mytextfile.txt")
Understanding the basic organization of classes within My really helps to get a sense of the kinds of uses to which these language extensions are suited:
There's so much going on here that it will take some time to explore and learn the many capabilities (and time-saving techniques) available through My. You'll also find these MSDN articles helpful in that quest:
But if you put in the time and effort, you can count on reaping some righteous rewards!
Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. E-mail Ed at firstname.lastname@example.org with comments, questions, or suggested topics or tools to review.