Skip to Content
.NET Common Language Runtime Unleashed
book

.NET Common Language Runtime Unleashed

by Kevin Burton
April 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
23h 26m
English
Sams
Content preview from .NET Common Language Runtime Unleashed

Why delegates?

In the past, you could pass a function pointer, cast as an int, and it was up to the function being called to know what type of function pointer was passed. This improved somewhat with later versions of C where the return type of function, number of arguments, and argument type could all be specified. The problem is that it was not type-safe. One example that is used frequently is qsort. This function was passed a void pointer to what was to be sorted, the number of elements to be sorted, the size of the elements, and a comparison function. The call to qsort when you are sorting an array of int might look like this:

int a[100]
// Initialize array a
. . .
qsort((void *)a, 100, sizeof(int), compare);

The comparison routine would ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Customizing the Microsoft® .NET Framework Common Language Runtime

Customizing the Microsoft® .NET Framework Common Language Runtime

Steven Pratschner

Publisher Resources

ISBN: 0672321246Purchase book