Articles → CSHARP → Func Delegate In C#

Func Delegate In C#






Purpose





Example


using System;

namespace ConsoleApp2 {
  class Program {
    static void Main(string[] args) {
      Program program = new Program();

      Func <string, string> messageDelegate = program.Greet;

      Console.WriteLine(messageDelegate("Gyan"));
      Console.ReadLine();
    }

    public string Greet(string name) {
      return string.Format("Hello {0}", name);
    }
  }
}



Output


Picture showing the output of  func delegate in c#
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, February 24, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250