Tag Archives: arrays

Give a class default indexer properties in C#

An indexer property is a property that other code can use inside square brackets to access some value provided by the class, much as you can use the index of an array. Unlike an array, a class’s indexer need not … Continue reading

Posted in arrays, classes, syntax | Tagged , , , , , , , , , | Leave a comment

Loop over an array of unknown dimension in C#

The previous post Loop over entries in an array of unknown length in C# explains how to loop over the entries in a one- or two-dimensional array, but what do you do if you don’t know how many dimensions an … Continue reading

Posted in algorithms, arrays, recursion, variables | Tagged , , , , , , , , , , , , , , , , | 1 Comment

Loop over entries in an array of unknown length in C#

One way to loop through the items in an array is to hard code its length into the program. Alternatively you can use the array’s Length property to determine how many items it contains at runtime. Then if you later … Continue reading

Posted in arrays, variables | Tagged , , , , , , , , , , , , | Leave a comment

Get variable values by name in C#

The process for displaying variable values is somewhat convoluted, but it’s not too long. The example starts by using the following code to define some private and public fields. // Some form-level values. private string private_value1 = “This is private … Continue reading

Posted in arrays, reflection, variables | Tagged , , , , , , , , , , , , , , , | 1 Comment

Link ComboBox and ListBox data sources in C#

Few people know that you can link ComboBox and ListBox controls to data sources. If you set their DataSource property to an array or other object holding values, the control will display those values. This can be a convenient way … Continue reading

Posted in arrays, controls, database | Tagged , , , , , , , , , , , | Leave a comment

Sort and search arrays in C#

The Array class provides several useful methods for working with arrays. Two of them let you sort and search arrays. The following code shows how the program uses the Array class’s Sort method to sort an array of random data. … Continue reading

Posted in algorithms, arrays | Tagged , , , , , , , , , , , | Leave a comment

Initialize an array of arrays in C#

The example Initialize two-dimensional arrays in C# explains how to initialize a two-dimensional array. An array of arrays is somewhat similar to a two-dimensional array but with some syntax differences. The following code shows how this example declares and initializes … Continue reading

Posted in arrays, syntax | Tagged , , , , , , , , , , , | Leave a comment

Initialize two-dimensional arrays in C#

The example Initialize arrays, lists, and class instances in C# explains how to initialize a one-dimensional array. You can use a similar syntax to initialize multi-dimensional arrays. Use a new statement to indicate the type of array you are initializing. … Continue reading

Posted in arrays, syntax | Tagged , , , , , , , , , , | 1 Comment

Save a color palette in a program’s settings in C#

The example Make a persistent color palette in C# shows how a program can use settings to save and restore a color palette. The program saves the palette colors as a list of ARGB color values stored in a string … Continue reading

Posted in arrays, drawing, graphics, settings | Tagged , , , , , , , , , , , , | Leave a comment

Bind arrays and lists in C#

One way to display the items in an array in a ListBox is to loop through the items and add them to the ListBox one at a time, but there’s an easier way. You can bind arrays to a ListBox … Continue reading

Posted in arrays, controls, lists | Tagged , , , , , , , , , , , , | 2 Comments