Thursday, September 6, 2012

Action delegates in C#

In last few posts about I have written lots of things about delegates and this post is also part of that series. In this post we are going to learn about Action delegates in C#.  Following is a list of post related to delegates.

  1. Delegates in C#.
  2. Multicast Delegates in C#.
  3. Func Delegates in C#.

Action Delegates in c#:

As per MSDN action delegates used to pass a method as parameter without explicitly declaring custom delegates. Action Delegates are used to encapsulate method that does not have return value. C# 4.0 Action delegates have following different variants like following. It can take up to 16 parameters.

  • Action – It will be no parameter and does not return any value.
  • Action(T)
  • Action(T1,T2)
  • Action(T1,T2,T3)
  • Action(T1,T2,T3,T4)
  • Action(T1,T2,T3,T4,T5)
  • Action(T1,T2,T3,T4,T5,T6)
  • Action(T1,T2,T3,T4,T5,T6,T7)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16)
Share:
Wednesday, September 5, 2012

Incremental search in Visual Studio

Visual studio is a Great IDE and there are still lots of feature that not known to developers. Incremental search is one of them. This is a amazing feature to find code in particular document and its available from Visual Studio 2010 and carried over in Visual Studio 2012. Incremental search allows developers to search in document without blocking UI and allow to search as they type.

Interesting!! right.. So let’s open visual studio and see how it works. Once you open Visual Studio and press Ctrl + I and type something it will find the string without blocking your visual studio UI. Just like following.

Incremental Search in Visual Studio
Share:
Saturday, August 25, 2012

Func Delegate in C#

We already know about delegates in C# and I have previously posted about basics of delegates in C#. Following are posts about basic of delegates I have written.

Delegates in C#
Multicast Delegates in C#

In this post we are going to learn about Func Delegates in C#. As per MSDN following is a definition.

“Encapsulates a method that has one parameter and returns a value of the type specified by the TResult parameter.”

Func can handle multiple arguments. The Func delegates is parameterized type. It takes any valid C# type as parameter and you have can multiple parameters as well you have to specify the return type as last parameters.

Followings are some examples of parameters.
Func<int T,out TResult>
Func<int T,int T, out Tresult>

Now let’s take a string concatenation example for that. I am going to create two func delegate which will going to concate two strings and three string. Following is a code for that.

using System;
using System.Collections.Generic;

namespace FuncExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string, string> concatTwo = (x, y) => string.Format("{0} {1}",x,y);
            Func<string, string, string, string> concatThree = (x, y, z) => string.Format("{0} {1} {2}", x, y,z);

            Console.WriteLine(concatTwo("Hello", "Jalpesh"));
            Console.WriteLine(concatThree("Hello","Jalpesh","Vadgama"));
            Console.ReadLine();
        }
    }
}

Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews