Posts Tagged delegate

Fastest Callbacks: Delegate, Event, or Interface?

Tags: , ,

How fast are C# delegates and events? The best answer is “compared to what?”. You probably use callbacks all the time, but what’s the fastest kind of callback? C# delegates and events are nice, built-in features of C#, but you could also implement your own callback interface. Would that gain you any speed? Read on for the performance test and results!

Read the rest of this article »

8 Comments

Unity Function Performance

Tags: , , , , ,

Which is the fastest kind of C# function in Unity? There are several to choose from: regular old instance methods, static methods, delegates, and lambdas. Is there any performance reason to choose one over the other? Today’s article answers just these questions by putting each type of function to the test. Read on to see which is fastest and which is slowest!

Read the rest of this article »

4 Comments

Capturing and Forwarding Unity Events

Tags: ,

As mentioned in last week’s article on the “pure code” approach to Unity code design, capturing events can be problematic. I gave an example of how this could be overcome, but didn’t flesh it out to cover the sixty events that a MonoBehaviour can receive. Today’s article includes the source code for a class that does just that. It should prove useful to anyone interested in exploring “pure code” design.

Read the rest of this article »

23 Comments

From AS3 to C#, Part 16: Lambdas and Delegates

Tags: , , ,

Two of C#’s really interesting features are technically operators, but didn’t fit in last week’s article. These are both ways to create anonymous functions: lambdas and delegates. AS3 has anonymous functions too, but today’s article will discuss how they differ from the C# approaches. Read on to learn how to harness the power of anonymous functions in C#.

Read the rest of this article »

1 Comment

From AS3 to C#, Part 11: Generic Classes, Interfaces, Methods, and Delegates

Tags: , , , ,

Continuing once again, today we cover an exciting new topic: generics! Have you ever wished your classes could be parameterized with a type like Vector.<Type> is? With C# generics, you can! Even better, you can parameterize your interfaces, methods, and delegates too. Read on to learn how.

Read the rest of this article »

12 Comments

From AS3 to C#, Part 9: Even More Special Functions

Tags: ,

Last week’s article continued the discussion of special types of functions in C#’s class system, including variable numbers of arguments (“var args”), indexers, and conversion operators. Today’s article should finish up the topic of special functions. Read on to learn about the built-in support for delegates, events, and object initializers!

Read the rest of this article »

3 Comments