1. Skip to content
  2. Skip to sidebar

‹ Showing all posts tagged as ‘Lambda’ ›

One Response to "How to Improve Code Reusability Using C# Delegates"

  1. Very interesting! Your use of delegates reminds me of the Strategy Pattern, but allows for much quicker and more concise implementation for “simpler” strategies because the developer doesn’t have to implement a whole interface which describes the “small” strategy and entire subclasses to implement the strategy. It’s definitely going into my repertoire of C# programming techniques.

    I hope you don’t mind that I nitpick a little, and do correct me if I’m wrong, but I found your statement that “delegates in C# allow you to assign a type to a particular method signature” left me a little confused for a bit because “method signature” typically refers to the method’s name, order of parameters, and type of parameters. However, it seems the delegates assign not only the order and type of parameters but also the return type of the function, and it does not assign it a name. For me who doesn’t have much experience using delegates, it would have been much clearer to say “delegates in C# allow you to assign a method type to a particular order and type of parameters and return type”, so I wouldn’t mistakenly believe delegates restrict the method name.

Leave a Reply:

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*

How to Improve Code Reusability Using C# Delegates

Delegates are a powerful, functional language feature of C# that are heavily utilized but rarely implemented by most developers who are not familiar of the advantages they give you. Similar to function pointers in C/C++, delegates in C# allow you … Continue reading

One Response to "How to Improve Code Reusability Using C# Delegates"

  1. Very interesting! Your use of delegates reminds me of the Strategy Pattern, but allows for much quicker and more concise implementation for “simpler” strategies because the developer doesn’t have to implement a whole interface which describes the “small” strategy and entire subclasses to implement the strategy. It’s definitely going into my repertoire of C# programming techniques.

    I hope you don’t mind that I nitpick a little, and do correct me if I’m wrong, but I found your statement that “delegates in C# allow you to assign a type to a particular method signature” left me a little confused for a bit because “method signature” typically refers to the method’s name, order of parameters, and type of parameters. However, it seems the delegates assign not only the order and type of parameters but also the return type of the function, and it does not assign it a name. For me who doesn’t have much experience using delegates, it would have been much clearer to say “delegates in C# allow you to assign a method type to a particular order and type of parameters and return type”, so I wouldn’t mistakenly believe delegates restrict the method name.

Leave a Reply:

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*

back to top

IList<T> Sorting: A Better Way

Programming forums across the web are replete with questions about how to sort an IList. Many .NET developers have discovered that, unlike List<T>, IList<T> does not define a Sort() method. Although there are many excellent answers to the question of … Continue reading

2 Responses to "IList<T> Sorting: A Better Way"

  1. Miguel says

    This code does not compile. It complaints at :
    return list.OrderBy(t => t, new ComparisonComparer(comparison));
    Saying:
    Error No overload for method ‘OrderBy’ takes 2 arguments SorExtensions.cs

  2. David Mills says

    Hi Miguel,

    Thanks for the feedback. Have you added a “using” statement for Velir.Extensions at the top of your code file? The error message you describe is what you might get if you hadn’t yet referenced the SortExtensions class, like so:

    using Velir.Extensions;


    Edit: I misread your question initially. Can you verify that you’re working with Visual Studio 2008 and .NET Framework 3.5 or above?

Leave a Reply:

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*

back to top