Solved

What does "Func<string, int> method = Work;" do?

Posted on 2010-08-19
6
248 Views
Last Modified: 2013-12-17
I am not familar with this, please explain.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 3
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
rajvja earned 250 total points
Comment Utility
Hi,

   Func is the function name
  It will take 2 parameters. 1. string value, 2. integer value

It is like GetFirstName('abc def',3) = abc

0
 
LVL 27

Assisted Solution

by:nmarun
nmarun earned 250 total points
Comment Utility
Read http://www.codeproject.com/KB/cs/DelegatesOMy.aspx for a detailed article on lambda expressions.

Arun
0
 

Author Comment

by:newbieweb
Comment Utility
It's used here:

static void Main()
{
  Func<string, int> method = Work;
  method.BeginInvoke ("test", Done, method);
  // ...
  //
}
 
static int Work (string s) { return s.Length; }
 
static void Done (IAsyncResult cookie)
{
  var target = (Func<string, int>) cookie.AsyncState;
  int result = target.EndInvoke (cookie);
  Console.WriteLine ("String length is: " + result);
}
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:newbieweb
Comment Utility
Is Func a delegate
0
 
LVL 27

Expert Comment

by:nmarun
Comment Utility
Yes it is... read the article I posted.. it'll tell you all you need to know about 'Func'.

Arun
0
 

Author Closing Comment

by:newbieweb
Comment Utility
Thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now