Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,859 questions

51,780 answers

573 users

How to use the Func delegate in C#

3 Answers

0 votes
using System;

class Program
{
    static string AMessage() {
        return "May the Force be with you";
    }
    
    static void Main() {
        Func<string> say = AMessage;
        
        Console.WriteLine(say());
    }
}



/*
run:

May the Force be with you

*/

 



answered Jul 1, 2023 by avibootz
0 votes
using System;

class Program
{
    static int Sum(int x, int y) {
        return x + y;
    }
    
    static void Main() {
        Func<int, int, int> add = Sum;

        int result = add(5, 5);

        Console.WriteLine(result); 
    }
}



/*
run:

10

*/

 



answered Jul 1, 2023 by avibootz
0 votes
using System;

class Program
{
    static int Sum(int x, int y, int z) {
        return x + y + z;
    }
    
    static void Main() {
        Func<int, int, int, int> add = Sum;

        int result = add(5, 5, 5);

        Console.WriteLine(result); 
    }
}



/*
run:

15

*/

 



answered Jul 1, 2023 by avibootz

Related questions

1 answer 93 views
93 views asked Jul 1, 2023 by avibootz
1 answer 90 views
1 answer 105 views
1 answer 92 views
1 answer 132 views
1 answer 116 views
3 answers 153 views
153 views asked Jul 2, 2023 by avibootz
...