DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Role of C# in Building Dynamic and Secure Web Applications
  • How to LINQ Between Java and SQL With JPAStreamer
  • Unlocking the Potential of Binary Search Trees with C# Programming
  • C# vs. Python vs. C++ for Game Development

Trending

  • Designing a Java Connector for Software Integrations
  • Mastering Advanced Aggregations in Spark SQL
  • Is Agile Right for Every Project? When To Use It and When To Avoid It
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks

Func Delegate in C#

By 
Jalpesh Vadgama user avatar
Jalpesh Vadgama
·
Aug. 25, 12 · Interview
Likes (0)
Comment
Save
Tweet
Share
14.9K Views

Join the DZone community and get the full member experience.

Join For Free
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 and also you have 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();
}
}
}

As you can see in above example, I have create two delegates ‘concatTwo’ and ‘concatThree. The first concat two strings and another concat three strings. If you see the func statements the last parameter is for the out as here its output string so I have written string as last parameter in both statements. Now it’s time to run the example and as expected following is output.

Func delegate in c#

That’s it. Hope you like it. Stay tuned for more updates.

csharp

Published at DZone with permission of Jalpesh Vadgama, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Role of C# in Building Dynamic and Secure Web Applications
  • How to LINQ Between Java and SQL With JPAStreamer
  • Unlocking the Potential of Binary Search Trees with C# Programming
  • C# vs. Python vs. C++ for Game Development

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: