Problem:
You want an efficient method to swap two elements that exist within a single array.
Solution:
Use the generic SwapElementsInArray<T> method:
public static void SwapElementsInArray<T>(T[] theArray, int index1, int index...
Problem:
You want an efficient method to reverse the order of elements within an array.
Solution:
You can use the static Reverse method, as in this snippet of code:
int[] someArray = new int[5] {1,2,3,4,5};
Array.Reverse(someArray);
...
Problem:
You need to reverse each row in a two-dimensional array. The Array.Reverse method does not support this operation.
Solution:
Use the following Reverse2DimArray<T> method:
public static void Reverse2DimArray<T>(T[,] the...
Problem:
The Array.Reverse method does not provide a way to reverse each subarray in a jagged array. You need this functionality.
Solution:
Use the ReverseJaggedArray<T> method:
public static void ReverseJaggedArray<T>(T[][] th...
Problem:
You have a StackTrace object that contains a listing of stack frames. You need to iterate through these stack frames as if you were using a Collection-type object.
Solution:
Wrap the public interface of a StackTrace object to look lik...
Determining the Number of Times an Item Appears in a List<T>
Problem:
You need the number of occurrences of one type of object contained in a List<T>. The List<T> contains methods, such as Contains and BinarySearch to find a s...
Retrieving All Instances of a Specific Item in a List<T>
Problem:
You need to retrieve every object contained in a List<T> that matches a search criterion. The List<T> contains the BinarySearch method to find a single itemesse...
Problem:
You need the ability to insert and remove items from a standard System.Array type. When an item is inserted, it should not overwrite the item where it is being inserted; instead, it should be inserted between the element at that index and t...
Keeping Your List<T> Sorted
Problem:
You will be using the BinarySearch method of the List<T> to periodically search the List<T> for specific elements. The addition, modification, and removal of elements will be interleaved wi...
Problem:
You want to sort the keys and/or values contained in a Hashtable in order to display the entire Hashtable to the user, sorted in either ascending or descending order.
Solution:
Use the Keys and Values properties of a Dictionary<T,U...
Problem:
You need to use a generic Dictionary object in your project that stores only numeric data in its value (the key can be of any type)between a set maximum and minimum value.
Solution:
Create a class with accessors and methods that enfor...
Problem:
You have an array or type that implements ICollection, and you wish to display or store it as a string delimited by commas or some other delimiting character. This ability will allow you to easily save data stored in an array to a text file...
Problem:
You have an ArrayList, Queue, or Stack object and you want to take a snapshot of its current state. (Note that this recipe also works for any other data type that implements the ICollection interface.)
Solution:
Use the CopyTo method ...
Problem:
You have a collection such as an ArrayList, List<T>, Hashtable, or Dictionary<T,U> in which you are storing application information. You can use this information to tailor the application's environment to the last known settings...
Testing Every Element in an Array or List<T>
Problem:
You need an easy way to test every element in an Array or List<T>. The results of this test should indicate that the test passed for all elements in the collection or it failed f...
Performing an Action on Each Element in an Array or List<T>
Problem:
You need an easy way to iterate over all the elements in an Array or List<T>, performing an operation on each element as you go.
Solution:
Use the ForEach me...
Creating a Read-Only Array or List<T>
Problem:
You need a way to create a read-only Array or List<T>, where the Array or List<T> itself is read-only.
Solution:
Use the AsReadOnly method of the Array or List<T> clas...
AJAX popular information C# language guides Windows books and cookbooks
.......
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.