More Read-Only Examples

Another couple of ways that you can make a collection read-only is by applying a AsReadOnly() method or by using ReadOnlyCollection. This is just another way that you can expose collection details. For example if you want to expose the element details to another layer of the program for display purposes only. This is one way you can do it.

Continue reading


IReadOnlyCollection Interface Usage

This short program shows how read-only collections can be used. There have been times where I’ve wanted to expose the elements of a collection without giving the ability to change any elements. Just view them. From there if the collection needs to be modified it will have to be cast as another variable.

Granted it’s that way in most cases. I was messing around and was taught a way to modify the collection by way of casting an array object. I’ll demonstrate in the code.

Continue reading

Binary Searching Of Arrays

Another way of searching large arrays in a more effective/efficient way is to do a binary search.

How does this work different that the methods from the Find Elements program?  Those other methods load all of the array elements in memory and then perform searches. As you can imagine this put quite the workload on the computer and possibly have out of memory exceptions depending on your environment.

With a binary search it basically uses an algorithm takes small chunks of the array, loads them in memory, and searches thru that. This method only has a benefit on large arrays. The typical rule is if the array is over 100 elements use this method. Otherwise use the more linear approaches from the other methods.

Continue reading