using System;
namespace FuncDemo
{
internal class Program
{
private static void Main()
{
//类似委托功能
Func<InputArgs, Result> func = TsetFunction;
Console.WriteLine("第一种方式:");
Console.WriteLine(func(new InputArgs("zhangqs008", "123456")));
Console.WriteLine("=============================================");
Console.WriteLine("第二种方式:");
CallMethod(func, new InputArgs("zhangqs008", "1234567")); //或者
CallMethod(TsetFunction, new InputArgs("zhangqs008", "1234567"));
Console.Read();
}
public static Result TsetFunction(InputArgs input)
{
Result result = new Result();
result.Flag = String.Compare("zhangqs008", input.UserName, StringComparison.OrdinalIgnoreCase) == 0 &
String.Compare("123456", input.Password, StringComparison.OrdinalIgnoreCase) == 0;
result.Msg = "当前调用者:" + input.UserName;
return result;
}
public static void CallMethod<T>(Func<T, Result> func, T item)
{
Result result = func(item);
Console.WriteLine(result.ToString());
}
/// <summary>
/// 方法参数
/// </summary>
public class InputArgs
{
public InputArgs(string userName, string password)
{
UserName = userName;
Password = password;
}
public string UserName { get; set; }
public string Password { get; set; }
}
/// <summary>
/// 方法结果
/// </summary>
public class Result
{
public string Msg { get; set; }
public bool Flag { get; set; }
public override string ToString()
{
return string.Format("Flag:{0},Msg:{1}", Flag, Msg);
}
}
}
}
分享到:
相关推荐
void ActivationEventBeginInvoke(Func<int> id,Action<IEnumerable<T>> TValue = null, Action<IAsyncResult> Ting=null); IEnumerable<T> GetChildList(); void GetChildList(Action<IEnumerable<T>> TValue)...
<br/><br/>\admin 目录<br/>\admin\database.inc.php<br/>\admin\forums....func.php<br/>\include\category.inc.php<br/>\include\common.inc.php<br/>\include\cron.func.php<br/>\include\discuzcode.func.php<br/>\...
version.php<br/>\my.php<br/>\pm.php<br/>\search.php<br/>\stats.php<br/>\...func.php<br/>\include\common.inc.php<br/>\include\common.js<br/>\include\discuzcode.func.php<br/>\include\editor.func.php<br/>\...
这个方法可以从Func<T1 , T2 , TResult>委托中引用,其中T1 和T2 的类型相同:Func<T , T , bool>。 给Sort<T>方法指定下述签名: public static void Sort<T>(IList<T> sortArray, Func<T, T, bool> comparsion...
#region 3.2 根据指定条件 修改 +int ModifyBy(Expression<Func<T, bool>> whereLambda) /// <summary> /// 2.3 根据指定条件 修改 /// </summary> /// <param name="whereLambda">条件表达式</param> /// ...
<div class='top_bar_text' id='365riliUserName'></div> <div class='top_bar_text' id='bd_login'>登录</div> </div> </div> </div> <div id='cal_down'> <div id='cal_downleft'> <div id='mainCal'></...
ref就是复制 复制是不会影响原始数据的 <template> <div> <div> <div>{{stateObj}}</div> <button @click="func1">按钮</button> </div> </div> </template> <script> import {ref} from 'vue' export ...
增加执行C/C++函数的HTML标记<%func()%>。在C/C++函数中执行printf后的输出文本可自动插入到HTML中。<br/>15. 用户以前编写的C/C++程序,稍加修改便可嵌入到web页面中。<br/>16. 自动检测堆栈是否溢出,资源是否...
Func<T>、Action<T> 的区别于说明 一、Func Func是一个.Net内置的委托。 Func<Result>,Func<T1>是一个.Net内置的泛型委托。 Func<TResult> Func<T> Func<T1> Func<T1> Func<T1> 它有5种形式,只是参数个数不同;第...
.NET Framework也可对某些现有泛型接口和委托带来不同的支持,包括IEnumerable<(Of <(T>)>)接口和Func<(Of <(TResult>)>) 与 Action<(Of <(T>)>) 委托。 新的命令行选项 /langversion命令行选项可让编译器接受只在...
将Expression<Func<T>>表达式转为Expression<Func<T, object>>
XML,Ajax,C# 编写.<br><br>admin 是管理后台<br><br>func脚本文件 Ajax<br><br>Ajfunc 是处理Ajax的C#代码<br><br>.NET2.0 环境.<br>
本文主要介绍Func<T>和Action<T>的用法以及他们之间的区别,希望对大家有所帮助
记录笔记 ... Func <TResult> 例外 GC 特性最大生成 方法 收集(Int32) CollectionCount(Int32) GetGeneration(对象) GetTotalMemory(布尔) SuppressFinalize(对象) WaitForPendingFinali
启用通用包装器: Func<T> Lazy<T> Expression<Func>> 您可能已经定义了任何其他通用包装器。 馆藏支持: IEnumerable<T> IReadOnlyCollection<T> IReadOnlyList<T> T[] List<T> ICollection<T> IList<T> HashSet<T...
%SM56_HDAUDIO_MODEM_INSTALL% = SM56_HDAUDIO_MODEM_INSTALL, HDAUDIO\FUNC_02&VEN_1057&DEV_3055&SUBSYS_10573055&REV_0701 %SM56_HDAUDIO_MODEM_INSTALL% = SM56_HDAUDIO_MODEM_INSTALL, HDAUDIO\FUNC_02&VEN_...
%SM56_HDAUDIO_MODEM_INSTALL% = SM56_HDAUDIO_MODEM_INSTALL, HDAUDIO\FUNC_02&VEN_1057&DEV_3055&SUBSYS_10573055&REV_0701 %SM56_HDAUDIO_MODEM_INSTALL% = SM56_HDAUDIO_MODEM_INSTALL, HDAUDIO\FUNC_02&VEN_...
.NET Standard 2.1、.NET 5、.NET 6、.NET 7 版本SQLBuilder,Expression表达式转换为SQL语句,支持SqlServer、MySql、Oracle、Sqlite、PostgreSql;基于Dapper实现了不同数据库对应的数据仓储Repository;
使用Func<T>,我们轻松实现,看代码: 代码如下:/// <summary>/// LazyExpression/// </summary>/// <typeparam name=”T”>T</typeparam>public class LazyExpression<T>{ Func<T> thunk; public Lazy[removed]
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h> typedef struct matrix { int row; int col; } matrix; typedef struct minCost { int cost; int mid; } minCost; minCost** ...