ADBRITE ads links
You are here: CodeIdol.com > C# > C# Cookbook, 2nd Edition > Unsafe Code
C# Cookbook, 2nd Edition
| Problem:
You must pass a pointer variable to a method; however, you do not want to allow the called method to change the address that the pointer points to. For example, a developer wants to assume that, after passing a pointer parameter to a method...
|
|
| Problem:
You need to know whether two pointers point to the same memory location. If they don't, you need to know which of the two pointers points to a higher or lower element in the same block of memory.
Solution:
Using the == and != operator...
|
|
| Problem:
You need to iterate through the elements of a single-dimensional, multidimensional, or jagged array using a pointer to that array.
Solution:
To enable iteration, create an unsafe pointer that points to an array. The manipulation of th...
|
|
| Problem:
One limitation of a pointer to a fixed array is that you cannot reassign this pointer to any other element of that array using pointer arithmetic. The following code will not compile since you are attempting to modify where the fixed pointe...
|
|
| Problem:
You need to create a method that accepts a pointer to an array, searches that array for a particular element, and returns to the location of the found element in the array.
Solution:
The FindInArray method, used in the following examp...
|
|
| Problem:
You need to create, initialize, and use an array containing pointers.
Solution:
The following code creates three pointers to a NewBrush structure (theNewBrush1, theNewBrush2, and theNewBrush3) that are inserted as elements in an array...
|
|
| Problem:
You need a generic method that accepts two pointers and switches the addresses that each pointer points to. In other words, if x points to an integer variable Foo and y points to an integer variable Bar, you want to switch x so that it poin...
|
|
| Problem:
You have a string that you want to convert to a char*, which is essentially a pointer to the first element in a character array.
Solution:
Use the ToCharArray method of the string type to create a char* character array:
public sta...
|
|
| Problem:
You require a structure to contain a fixed-size array in which the array is not stored on the managed heap; rather, the array needs to be stored inside the structure on the stack. This type of structure is useful when an unmanaged method th...
|
|
You are here: CodeIdol.com > C# > C# Cookbook, 2nd Edition > Unsafe Code
|
|
Related tags
Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......
|
|