不同数据类型的Linq
创始人
2025-01-09 18:30:14
0

在LINQ中,可以使用不同的数据类型进行查询和操作。下面是几种常见的数据类型及其对应的LINQ代码示例:

  1. 数组(Array):
int[] numbers = { 1, 2, 3, 4, 5 };

var query = from num in numbers
            where num % 2 == 0
            select num;

foreach (var num in query)
{
    Console.WriteLine(num);
}
  1. 列表(List):
List names = new List { "Alice", "Bob", "Charlie", "David" };

var query = from name in names
            where name.Length > 4
            select name;

foreach (var name in query)
{
    Console.WriteLine(name);
}
  1. 字典(Dictionary):
Dictionary dictionary = new Dictionary
{
    { 1, "Apple" },
    { 2, "Banana" },
    { 3, "Cherry" }
};

var query = from pair in dictionary
            where pair.Value.StartsWith("A")
            select pair;

foreach (var pair in query)
{
    Console.WriteLine(pair.Key + ": " + pair.Value);
}
  1. 集合(Set):
HashSet set1 = new HashSet { 1, 2, 3, 4, 5 };
HashSet set2 = new HashSet { 4, 5, 6, 7, 8 };

var query = set1.Intersect(set2);

foreach (var num in query)
{
    Console.WriteLine(num);
}
  1. 数据表(DataTable):
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Age", typeof(int));

table.Rows.Add("Alice", 25);
table.Rows.Add("Bob", 30);
table.Rows.Add("Charlie", 35);

var query = from row in table.AsEnumerable()
            where row.Field("Age") > 30
            select row.Field("Name");

foreach (var name in query)
{
    Console.WriteLine(name);
}

这些示例展示了如何使用LINQ对不同数据类型进行查询和操作。可以根据实际需求进行相应的调整和扩展。

相关内容

热门资讯

透视教程!约局吧开挂,扑克之星... 透视教程!约局吧开挂,扑克之星辅助,原来真的是有挂(揭秘教程);1、这是跨平台的扑克之星辅助黑科技,...
透视脚本!werplan脚本,... 透视脚本!werplan脚本,hhpoker怎么防作弊(透视)一向有挂(透牌教程);1、hhpoke...
透视挂透视!sohoo开挂辅助... 透视挂透视!sohoo开挂辅助,来玩app 德州 辅助,好像有挂(软件教程)1、完成来玩app 德州...
透视好牌!sohoo开挂辅助,... 透视好牌!sohoo开挂辅助,wepoker公共底牌(透视)切实是真的有挂(可靠技巧);1)wepo...
透视透视!约局吧如何查看是否有... 透视透视!约局吧如何查看是否有挂,拱趴大菠萝万能辅助器,竟然真的是有挂(总结教程);1、约局吧如何查...
辅助透视!线上德州的辅助器是什... 辅助透视!线上德州的辅助器是什么,cloudpoker外挂(透视)确实是有挂(2025版教程)进入游...
透视能赢!pokeplus脚本... 透视能赢!pokeplus脚本,pokemmo脚本辅助器下载,竟然是有挂(安装教程)1、很好的工具软...
透视新版!wepoker免费透... 透视新版!wepoker免费透视脚本,xpoker透视辅助(透视)果然有挂(揭秘教程)1、完成wep...
透视辅助!约局吧德州可以透视吗... 透视辅助!约局吧德州可以透视吗,xpoker辅助工具,切实真的是有挂(专业教程)1、打开软件启动之后...
透视代打!wepokerplu... 透视代打!wepokerplus外挂,hhpoker辅助器(透视)一直有挂(透明挂教程)1、起透看视...