Deborah's Developer MindScape

         Tips and Techniques for Web and .NET developers.

Archive for August, 2010

August 29, 2010

Iterate Through the Properties of a Class

Filed under: C#,VB.NET @ 12:12 am

Reflection provides features to obtain information about loaded assemblies and the classes (and other types) within them. One of the many things you can do with reflection is to iterate through each of the properties of a class and access its values. This example uses a customer class. In C#: public class Customer {     […]

August 28, 2010

Divide a List into Equal Parts

Filed under: C#,VB.NET @ 6:43 pm

A recent post in the forums asked how to divide a generic list of items into separate lists of equal length. For example, take a list of integers as shown below. Divide the list into separate lists of equal size (plus one list for the remaining elements). In C#: List<int> dd = new List<int>() { […]

August 17, 2010

Setting WinForms Colors to a Named, RGB, or Hex Value

Filed under: C#,VB.NET,WinForms @ 11:45 pm

Sometimes you want to add a little color to your WinForms controls. WinForms comes with a large set of named colors that you can use. NOTE: Be sure to import a reference to System.Drawing. For example In C#: textBox1.BackColor = Color.Linen; In VB: textBox1.BackColor = Color.Linen But what if you want to display a color […]

August 14, 2010

Checking for Empty Strings

Filed under: C#,VB.NET @ 11:46 pm

The "old school" way to check for empty strings is to use the Trim function to remove any empty spaces and then either check for a length of 0 or a string value of "". In C#: var str = ""; if (str.Trim().Length == 0) {     MessageBox.Show("Please enter a value"); } In VB: Dim […]

August 13, 2010

Auto-Implemented Properties Part II

Filed under: C#,VB.NET @ 12:51 am

This prior post covered the basics of auto-implemented properties in C# and VB. This current post takes a closer look at some of the features of the auto-implemented properties and how they are different between VB and C#. C# auto-implemented properties have the following features: Getters and setters can have different access levels. Snippets are […]

August 10, 2010


Filed under: C#,VB.NET @ 1:36 am

If you work with Enum values, you may often need to convert between the Enum, an integer representation of the Enum (to store in a table for example), and the string representation of the Enum (to display to the user for example). .NET 4.0 makes this easier with the new TryParse method. This example uses […]

Visual Studio: Hide Selection

Filed under: C#,VB.NET,Visual Studio @ 1:12 am

Sometimes you just want to focus on a specific piece of code and you want the rest of it just out of your way. With Visual Studio 2010, you can hide any piece of code in your application using the new Hide Selection feature. For example, here is a piece of code in a SaveItem […]

© 2023 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs