个性化阅读
专注于IT技术分析

LINQ empty方法

本文概述

在LINQ中, Empty方法或运算符用于返回集合的空序列。

LINQ empty方法的语法

这是LINQ Empty方法的语法, 用于生成具有空序列的集合。

var result1 = Enumerable.Empty<int>();

在以上语法中, 我们定义了Empty()方法以生成一个空序列。

LINQ empty方法示例

这是用于生成集合的LINQ empty方法的示例, 其中包含空序列。

using System;
using System. Collections;
using System.Collections.Generic;
using System. Linq;
using System. Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
    class Programme2
    {
        static void Main(string[] args)
        {
/*here Enumerable.Empty<int>() method will generate the 
    zero elements. Here we do not want to return any value*/
            var result1 = Enumerable.Empty<int>();
            foreach (var item in result1)
            {
                Console.WriteLine(item);
            }
                Console.ReadLine();
        }
    }
}

在上面的示例中, 我们定义了Empty方法以生成一个空序列。如果运行上面的示例, 我们将得到空结果。这就是我们可以使用LINQ Empty()方法生成集合的空序列的方式。

输出

LINQ empty方法

赞(0)
未经允许不得转载:srcmini » LINQ empty方法

评论 抢沙发

评论前必须登录!