Don’t let yourself fooled by the title, we’ll discuss the topics of Globalization here. You’ll need the System.Globalization and System.Threading namespaces and possibly Sysglobl.dll to build custom cultures.
A little terminology: today, culture will mean the language, currency, date-format, calendar, writing system and different names of a given group of people. There are two types of cultures: neutral, which only provides information of the language spoken, and specific culture, which provides information about the region/country. For example “es” means the Spanish neutral culture, and “es-MX” means the Mexican culture with the appropriate region information (such as the unit of currency, date format, etc.). There’s also a special culture, called Invariant culture. This one is associated with the English language, but not with any region/country. You’ll use this one when you need consistency across different cultures in your application.
Continue reading “Format Data Based on Culture Information”
Here are the good news:
You should know only these!
Debugging and tracing are both enables you to log information about your application’s health, current status, etc. The main difference is that debugging is only allowed (it runs only) in debug mode. You can define a debug mode by adding the #define DEBUG command at the top of your code (or compiling your code with the /d:DEBUG flag.
We’ll cover the following classes and attributes in this post:
- Debugger Attributes
Continue reading “Debug and Trace a .NET Application”
As no doubt you’ll love it, .NET comes with the support of sending e-mail messages by SMTP. Unfortunately, it can’t act as a mail receiver, but we should overcome the pain and examine how to send emails with it.
The key namespace is System.Net.Mail, and there are two important classes: MailMessage, which represents an e-mail message, and SmtpClient, which provides methods to send it.
First let’s build our message by using the MailMessage class!
MailMessage represents an email message eager to be sent. It has the following constructors:
- MailAddress from, MailAddress to
- String from, String to
- String from, String to, String subject, String body
Don’t worry about MailAddress, it just takes a string and verifies that it is a valid e-mail address. It also defines some useful properties such as DisplayName or User. Use it instead of just passing a string.
Continue reading “Mailing and SMTP”
Delegates are object-oriented function pointers that safely encapsulate a method. A delegate must be of type delegate, define a return type and optionally a parameter list, like this:
public delegate void ImDelegate(int x, int y);
This delegate then can point to any methods which returns void and takes two integer values as parameters. To try our new delegate add the following code:
public static void Add(int x, int x)
ImDelegate handler = Add;
Continue reading “Using Delegates and Events”
The .NET Framework provides a set of classes to work with the file system, thus creating, modifying and opening files, directories, monitoring changes, etc. These classes live in the System.IO namespace. Here’s a brief list of them, and what they are capable of:
|Classes of System.IO
||Provides information about installed drives on the system.
||Static class with static methods to work with the directory system.
||A class to work with the directory system through instances of it.
||Static class with static methods to work with the file system.
||A class to work with the file system thorough instances of it.
||The base class of DirectoryInfo and FileInfo. Use it when you work with both, or extend it.
||Look for changes in a given location, and forwards them to your code.
Continue reading “Access Files and Folders by Using the File System Classes”
There are a bunch of reader/writer classes shipped with the .NET Framework. They inherit most of their functionality from the abstract TextReader/TextWriter class (except BinaryReader/Writer).
TextReader defines the following virtual methods:
- Peek: allows you to view the next character in a stream without advancing the cursor of the given reader class.
- Read: reads the next character from the stream and advances the cursor, too.
- Read(char buffer, int index, int count): reads the characters between the specified index position and count-1.
- ReadBlock: does exactly the same what the previous overload of Read.
- ReadLine: reads a line from the current stream.
- ReadToEnd: reads the current stream to the end.
TextWriter defines the following virtual methods:
- Flush: forces the content of the buffer to be written to the underlying device, thus clears it.
- Write: with 17 overloads, each one for writing a specific type.
- WriteLine: 18 overloads, each one for writing a specific type, and ending the line with the defined NewLine string.
Continue reading “Manage Data by Using Reader and Writer Classes”