博客
关于我
c# lambda表达式 LINQ
阅读量:347 次
发布时间:2019-03-04

本文共 843 字,大约阅读时间需要 2 分钟。

入门

在C#编程中,Func是非常重要的一种功能组合,它允许我们定义匿名函数,简化代码编写。以下是一个简单的示例:

using System;  namespace ConsoleApp5  {      class Program      {          static void Main(string[] args)          {              Func
func = new Func
((int a, int b) => { return a + b; }); int result = func(100, 200); // 300 Console.WriteLine(result); func = new Func
((int x, int y) => { return x * y; }); result = func(2, 3); // 6 Console.WriteLine(result); // 简化1 func = (x, y) => { return x * y; }; // 简化2 func = (x, y) => (x * y); // 6 Console.WriteLine(func(2, 3)); } } }

进阶

C#中的Func函数组合非常强大,它可以支持多种参数类型和返回类型。在实际开发中,Func常用于实现回调、事件处理或复杂逻辑的抽象化表达。通过对Func的理解和实践,你可以逐步掌握更复杂的编程逻辑和设计模式。

转载地址:http://vgce.baihongyu.com/

你可能感兴趣的文章
nio 中channel和buffer的基本使用
查看>>
NISP一级,NISP二级报考说明,零基础入门到精通,收藏这篇就够了
查看>>
NI笔试——大数加法
查看>>
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
Nmap扫描教程之Nmap基础知识
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>