Func
5197 ワード
using System;
delegate string ConvertMethod(string inString);
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
// Instantiate delegate to reference UppercaseString method
ConvertMethod convertMeth = UppercaseString;
string name = "Dakota";
// Use delegate instance to call UppercaseString method
outputBlock.Text = convertMeth(name) "
";
}
private static string UppercaseString(string inputString)
{
return inputString.ToUpper();
}
}
using System;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
// Instantiate delegate to reference UppercaseString method
Func<string, string> convertMethod = UppercaseString;
string name = "Dakota";
// Use delegate instance to call UppercaseString method
outputBlock.Text = convertMethod(name) "
";
}
private static string UppercaseString(string inputString)
{
return inputString.ToUpper();
}
}
using System;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
Func<string, string> convert = delegate(string s)
{ return s.ToUpper(); };
string name = "Dakota";
outputBlock.Text = convert(name) "
";
}
}
using System;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
Func<string, string> convert = s => s.ToUpper();
string name = "Dakota";
outputBlock.Text = convert(name) "
";
}
}