C#程序在列表中查找元素的多维数据集
使用Select方法和LambdaExpression计算元素的立方。
以下是我们的列表。
List<int> list = new List<int> { 2, 4, 5, 7 };现在,使用该Select()方法并计算多维数据集。
list.AsQueryable().Select(c => c * c * c);
以下是整个示例。
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> list = new List<int> { 2, 4, 5, 7 };
Console.WriteLine("Elements...");
//初始列表javascript:void
foreach (int n in list)
Console.WriteLine(n);
//每个元素的多维数据集
IEnumerable<int> res = list.AsQueryable().Select(c => c * c * c);
Console.WriteLine("Cube of each element...");
foreach (int n in res)
Console.WriteLine(n);
}
}输出结果
Elements... 2 4 5 7 Cube of each element... 8 64 125 343