Blogs from Microsoft C# Development Team

No Comments »

Want insight into the design and development of C#?  Then check out these blogs by key members of the Microsoft C# development team:

Read the rest of this entry »

Close All Forms in an Application in a Thread-Safe Manner


Closing all forms in an application seems like it would be a simple task of using a foreach loop in the Application.OpenForms collection, such as:

foreach (Form form in Application.OpenForms)

But there are two problems.

Read the rest of this entry »

C# Read String Line by Line


It’s easy to read a string one line at a time.  Here is a console program that demonstrates how:

Read the rest of this entry »

C# Convert String to Stream, and Stream to String


It’s fairly easy to convert a C# String to a Stream and vice-versa.

Read the rest of this entry »

Clear C# StringBuilder


Many .NET developers are baffled by the lack of a “Clear” method in the StringBuilder class.  For example, if you are using a StringBuilder in a loop, you may want to clear its contents at the beginning of each loop.

Read the rest of this entry »

Determine Windows Version and Edition with C#


This article explains how to use C# to determine the name, edition, service pack, version and bits of the host operating system.

For example, the results on my PC would be:

Operation System Information
Name = Windows Vista
Edition = Home Premium
Service Pack = Service Pack 1
Version = 6.0.6001.65536
Bits = 64

Read the rest of this entry »

C# Focus TextBox on Form Load


When showing a form that contains a TextBox, it’s common courtesy to focus the TextBox so that the user can begin typing immediately.

To focus a TextBox when a Windows Form first loads, simply set the TabIndex for the TextBox to zero (or the lowest TabIndex for any Control on the Form).

When a Form is displayed, it automatically focuses the Control with the lowest TabIndex.  Note that if your TextBox is pre-initialized with some text, then the entire Text will be selected, as shown below:

Entire text is selected

Read the rest of this entry »

C# Read Text File Line-by-Line


Here is the code to read a text file from disk one line at a time into a string.  This code ensures the file exists and properly closes the file if an exception occurs.

Read the rest of this entry »

C# Overloaded Methods with Inherited Arguments


This article discusses one of those programming topics that may be confusing at first but seems obvious once you know it.

As you know, C# enables you to overload the same method in a class with different arguments.  But it’s also possible to overload a method with arguments that inherit from one another.

Read the rest of this entry »

Find the Root of a C# Hierarchy


Many objects in .NET are stored in a hierarchy.  For example: controls, files and folders, and anything you would normally display in a tree view.  There are many different algorithms for finding the root of a hierarchy.  Here is one of them:

Read the rest of this entry »

« go backkeep looking »