Create a Func with string input and int value output in CSharp

Description

The following code shows how to create a Func with string input and int value output.

Example


/*  w w w.  jav  a 2  s  .c o  m*/
using System;
using System.ComponentModel;

class MainClass
{
    static void Main()
    {
        Func<string, int> returnLength = (text => text.Length);

        Console.WriteLine(returnLength("Hello"));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor